Method checks to see if a set of magnetic moments are collinear
        with each other.
        :param magmoms: list of magmoms (Magmoms, scalars or vectors)
        :return: bool
502663
def are_collinear(magmoms):
        
        magmoms = [Magmom(magmom) for magmom in magmoms]
        if not Magmom.have_consistent_saxis(magmoms):
            magmoms = Magmom.get_consistent_set(magmoms)

        # convert to numpy array for convenience
        magmoms = np.array([list(magmom) for magmom in magmoms])
        magmoms = magmoms[np.any(magmoms, axis=1)] # remove zero magmoms
        if len(magmoms) == 0:
            return True

        # use first moment as reference to compare against
        ref_magmom = magmoms[0]
        # magnitude of cross products != 0 if non-collinear with reference
        num_ncl = np.count_nonzero(np.linalg.norm(np.cross(ref_magmom, magmoms), axis=1))
        if num_ncl > 0:
            return False
        else:
            return True
659101
private static boolean checkVerticesForIntersection_(
			MultiVertexGeometryImpl geom, RasterizedGeometry2D rgeom) {
		// Do a quick raster test for each point. If any point is inside, then
		// there is an intersection.
		int pointCount = geom.getPointCount();
		Point2D pt = new Point2D();
		for (int ipoint = 0; ipoint < pointCount; ipoint++) {
			geom.getXY(ipoint, pt);
			RasterizedGeometry2D.HitType hit = rgeom.queryPointInGeometry(pt.x,
					pt.y);
			if (hit == RasterizedGeometry2D.HitType.Inside) {
				return true;
			}
		}

		return false;
	}
773709
function isRelated(a, b) {
  if (a.measurementAvg === b.measurementAvg) return true;
  if (a.relatedNames &&
      a.relatedNames.has(b.measurementAvg)) {
    return true;
  }
  if (b.relatedNames &&
      b.relatedNames.has(a.measurementAvg)) {
    return true;
  }
  return false;
}
934166
def _are_aligned_angles(self, b1, b2):
        ""
        return abs(b1 - b2) <= self.angle_tol or abs(np.pi - abs(b1 - b2)) <= self.angle_tol
1244950
def _unique_coords(self, coords_in, magmoms_in=None, lattice=None):
        
        coords = []
        if magmoms_in:
            magmoms = []
            if len(magmoms_in) != len(coords_in):
                raise ValueError
            for tmp_coord, tmp_magmom in zip(coords_in, magmoms_in):
                for op in self.symmetry_operations:
                    coord = op.operate(tmp_coord)
                    coord = np.array([i - math.floor(i) for i in coord])
                    if isinstance(op, MagSymmOp):
                        # Up to this point, magmoms have been defined relative
                        # to crystal axis. Now convert to Cartesian and into
                        # a Magmom object.
                        magmom = Magmom.from_moment_relative_to_crystal_axes(
                            op.operate_magmom(tmp_magmom),
                            lattice=lattice
                        )
                    else:
                        magmom = Magmom(tmp_magmom)
                    if not in_coord_list_pbc(coords, coord,
                                             atol=self._site_tolerance):
                        coords.append(coord)
                        magmoms.append(magmom)
            return coords, magmoms
        else:
            for tmp_coord in coords_in:
                for op in self.symmetry_operations:
                    coord = op.operate(tmp_coord)
                    coord = np.array([i - math.floor(i) for i in coord])
                    if not in_coord_list_pbc(coords, coord,
                                             atol=self._site_tolerance):
                        coords.append(coord)
            return coords, [Magmom(0)] * len(coords)
1337444
def issymmetric(am):
    
    """
    if am.shape[0] != am.shape[1]:
        logger.warning('Matrix is not square, symmetrical is irrelevant')
        return False
    if am.format != 'coo':
        am = am.tocoo(copy=False)
    if istril(am) or istriu(am):
        return False
    # Compare am with its transpose, element wise
    sym = ((am != am.T).size) == 0
    return sym
901955
def number_of_unique_magnetic_sites(self, symprec=1e-3, angle_tolerance=5):
        

        structure = self.get_nonmagnetic_structure()

        sga = SpacegroupAnalyzer(
            structure, symprec=symprec, angle_tolerance=angle_tolerance
        )

        symm_structure = sga.get_symmetrized_structure()

        num_unique_mag_sites = 0

        for group_of_sites in symm_structure.equivalent_sites:
            if group_of_sites[0].specie in self.types_of_magnetic_specie:
                num_unique_mag_sites += 1

        return num_unique_mag_sites
281035
def mag_pmf(matrix):
    
    nmags, ndists, nlons, nlats, neps = matrix.shape
    mag_pmf = numpy.zeros(nmags)
    for i in range(nmags):
        mag_pmf[i] = numpy.prod(
            [1. - matrix[i, j, k, l, m]
             for j in range(ndists)
             for k in range(nlons)
             for l in range(nlats)
             for m in range(neps)])
    return 1. - mag_pmf
719735
def isCollinear(self, b, c):
        '''
        
        '''

        return all(self.ccw(b, c, axis) == 0 for axis in self._keys)
996808
def magnetic_species_and_magmoms(self):
        

        structure = self.get_ferromagnetic_structure()

        magtypes = {
            str(site.specie): set()
            for site in structure
            if site.properties["magmom"] != 0
        }

        for site in structure:
            if site.properties["magmom"] != 0:
                magtypes[str(site.specie)].add(site.properties["magmom"])

        for sp, magmoms in magtypes.items():
            if len(magmoms) == 1:
                magtypes[sp] = magmoms.pop()
            else:
                magtypes[sp] = sorted(list(magmoms))

        return magtypes
181014
def aspectMalefics(self):
        
        malefics = [const.MARS, const.SATURN]
        return self.__aspectLists(malefics, aspList=[0, 90, 180])
1308346
def get_coordination_symmetry_measures(self, only_minimum=True,
                                           all_csms=True, optimization=None):
        
        test_geometries = self.allcg.get_implemented_geometries(
            len(self.local_geometry.coords))
        if len(self.local_geometry.coords) == 1:
            if len(test_geometries) == 0:
                return {}
            result_dict = {'S:1': {'csm': 0.0, 'indices': [0], 'algo': 'EXPLICIT',
                                   'local2perfect_map': {0: 0}, 'perfect2local_map': {0: 0},
                                   'scaling_factor': None, 'rotation_matrix': None, 'translation_vector': None}}
            if all_csms:
                for csmtype in ['wocs_ctwocc', 'wocs_ctwcc', 'wocs_csc', 'wcs_ctwocc', 'wcs_ctwcc', 'wcs_csc']:
                    result_dict['S:1']['csm_{}'.format(csmtype)] = 0.0
                    result_dict['S:1']['scaling_factor_{}'.format(csmtype)] = None
                    result_dict['S:1']['rotation_matrix_{}'.format(csmtype)] = None
                    result_dict['S:1']['translation_vector_{}'.format(csmtype)] = None
            return result_dict
        result_dict = {}
        for geometry in test_geometries:
            self.perfect_geometry = AbstractGeometry.from_cg(cg=geometry,
                                                             centering_type=self.centering_type,
                                                             include_central_site_in_centroid=
                                                             self.include_central_site_in_centroid)
            points_perfect = self.perfect_geometry.points_wcs_ctwcc()
            cgsm = self.coordination_geometry_symmetry_measures(geometry,
                                                                points_perfect=points_perfect,
                                                                optimization=optimization)
            result, permutations, algos, local2perfect_maps, perfect2local_maps = cgsm
            if only_minimum:
                if len(result) > 0:
                    imin = np.argmin([rr['symmetry_measure'] for rr in result])
                    if geometry.algorithms is not None:
                        algo = algos[imin]
                    else:
                        algo = algos
                    result_dict[geometry.mp_symbol] = {'csm': result[imin]['symmetry_measure'],
                                                       'indices': permutations[
                                                           imin],
                                                       'algo': algo,
                                                       'local2perfect_map':
                                                           local2perfect_maps[
                                                               imin],
                                                       'perfect2local_map':
                                                           perfect2local_maps[
                                                               imin],
                                                       'scaling_factor': 1.0 / result[imin]['scaling_factor'],
                                                       'rotation_matrix':
                                                           np.linalg.inv(result[imin]['rotation_matrix']),
                                                       'translation_vector': result[imin]['translation_vector']}
                    if all_csms:
                        self._update_results_all_csms(result_dict, permutations, imin, geometry)
            else:
                result_dict[geometry.mp_symbol] = {'csm': result,
                                                   'indices': permutations,
                                                   'algo': algos,
                                                   'local2perfect_map': local2perfect_maps,
                                                   'perfect2local_map': perfect2local_maps}
        return result_dict
518971
def _are_nearby_parallel_boxes(self, b1, b2):
        ""
        if not self._are_aligned_angles(b1.angle, b2.angle):
            return False
        # Otherwise pick the smaller angle and see whether the two boxes are close according to the "up" direction wrt that angle
        angle = min(b1.angle, b2.angle)
        return abs(np.dot(b1.center - b2.center, [-np.sin(angle), np.cos(angle)])) < self.lineskip_tol * (
            b1.height + b2.height) and (b1.width > 0) and (b2.width > 0) and (0.5 < b1.width / b2.width < 2.0)
603618
def _check_ising_quadratic_ranges(quad_ranges, graph):
        """"""
        if quad_ranges is None:
            quad_ranges = {}

        # first just populate the top level so we can rely on the structure
        for u in graph:
            if u not in quad_ranges:
                quad_ranges[u] = {}

        # next let's propgate and check what is already present
        for u, neighbors in iteritems(quad_ranges):
            for v, rang in iteritems(neighbors):
                # check the range
                rang = Specification._check_range(rang)

                if u in quad_ranges[v]:
                    # it's symmetric
                    if quad_ranges[u][v] != quad_ranges[v][u]:
                        raise ValueError("mismatched ranges for ising_quadratic_ranges")
                quad_ranges[v][u] = quad_ranges[u][v] = rang

        # finally fill in the missing stuff
        for u, v in graph.edges:
            if u not in quad_ranges[v]:
                quad_ranges[u][v] = quad_ranges[v][u] = [-1, 1]

        return quad_ranges
793142
def mag_calibration(self):
        """"""
        self.calibration_state = self.CAL_MAG
        self.mag_dialog = SK8MagDialog(self.sk8.get_imu(self.spinIMU.value()), self)
        if self.mag_dialog.exec_() == QDialog.Rejected:
            return

        self.calculate_mag_calibration(self.mag_dialog.samples)
333383
def spin2_polar(self):
        """"""
        return coordinates.cartesian_to_spherical_polar(
                                     self.spin2x, self.spin2y, self.spin2z)
898706
function(sbm) {
    // if the matrix ain't square, symmetry is off
    if (sbm.x !== sbm.y) {
      return false
    }

    // symmetry status
    var symmetry = true
    // iterate
    for (var i = 0; i < sbm.x; i++) {
      for (var j = 0; j <= i; j++) {
        symmetry = symmetry && ((_.includes(sbm.data[i], j) ^ _.includes(sbm.data[j], i)) === 0)
      }
    }
    // return
    return symmetry
  }