Beispiel #1
0
    def __init__(self,
                 optypes,
                 override_cn1=True,
                 cutoff_radius=8,
                 tol=1E-2,
                 cation_anion=False):

        self.optypes = optypes.copy()
        self.override_cn1 = override_cn1
        self.cutoff_radius = cutoff_radius
        self.tol = tol
        self.cation_anion = cation_anion

        if self.override_cn1 and self.optypes.get(1) != ["wt"]:
            raise ValueError(
                "If override_cn1 is True, optypes[1] must be ['wt']!")

        self.ops = {}
        for cn, t_list in self.optypes.items():
            self.ops[cn] = []
            for t in t_list:
                if t == "wt":
                    self.ops[cn].append(t)

                elif t[:4] == 'bent':
                    self.ops[cn].append(OrderParameters(
                        [t[:4]], parameters=[{'TA': float(t[4:]) / 180.0, \
                                              'IGW_TA': 1.0 / 0.0667}]))
                else:
                    self.ops[cn].append(OrderParameters([t]))
Beispiel #2
0
 def featurize(self, s, pneighs=None):
     """
     Calculate all sites' OPs.
 
     Args:
         s: Pymatgen Structure object.
         pneighs: (dict) specification and parameters of
                 neighbor-finding approach (see
                 get_neighbors_of_site_with_index function
                 in Pymatgen for more details).
 
         Returns:
             opvals: (2D array of floats) OP values of all sites'
             (1st dimension) order parameters (2nd dimension). 46 order
             parameters are computed per site: q_cn (coordination
             number), q_lin, 35 x q_bent (starting with a target angle
             of 5 degrees and, increasing by 5 degrees, until 175 degrees),
             q_tet, q_oct, q_bcc, q_2, q_4, q_6, q_reg_tri, q_sq, q_sq_pyr.
     """
     opvals = []
     ops = OrderParameters(self._types, self._paras, 100.0)
     for i, site in enumerate(s.sites):
         neighcent = get_neighbors_of_site_with_index(s, i, p=pneighs)
         neighcent.append(site)
         opvals.append(
             ops.get_order_parameters(
                 neighcent,
                 len(neighcent) - 1,
                 indeces_neighs=[j for j in range(len(neighcent) - 1)]))
         for j, opval in enumerate(opvals[i]):
             if opval is None:
                 opvals[i][j] = 0.0
     return opvals
def get_order_parameters(struct, pneighs={}, convert_none_to_zero=True):
    """
    Determine the neighbors around the site that has index n in the input
    Structure object struct, given a pre-defined approach.  So far,
    "scaled_VIRE" and "min_relative_VIRE" are implemented
    (VIRE = valence-ionic radius evaluator).

    Args:
        struct (Structure): input structure.
        pneighs (dict): specification ("approach") and parameters of
                neighbor-finding approach (see
                get_neighbors_of_site_with_index function
                for more details; default: min_relative_VIRE,
                delta_scale = 0.05, scale_cut = 4).
        convert_none_to_zero (bool): flag indicating whether or not
                to convert None values in OPs to zero.

    Returns: ([[float]]) matrix of all sites' (1st dimension)
            order parameters (2nd dimension). 46 order parameters are
            computed per site: q_cn (coordination number), q_lin,
            35 x q_bent (starting with a target angle of 5 degrees and,
            increasing by 5 degrees, until 175 degrees), q_tet, q_oct,
            q_bcc, q_2, q_4, q_6, q_reg_tri, q_sq, q_sq_pyr.
    """
    if pneighs == {}:
        pneighs = {
            "approach": "min_relative_VIRE",
            "delta_scale": 0.05,
            "scale_cut": 4
        }
    opvals = []
    optypes = ["cn", "lin"]
    opparas = [[], []]
    for i in range(5, 180, 5):
        optypes.append("bent")
        opparas.append([float(i), 0.0667])
    for t in ["tet", "oct", "bcc", "q2", "q4", "q6", "reg_tri", "sq", \
            "sq_pyr"]:
        optypes.append(t)
        opparas.append([])
    ops = OrderParameters(optypes, opparas, 100.0)
    for i, s in enumerate(struct.sites):
        neighcent = get_neighbors_of_site_with_index(struct, i, pneighs)
        neighcent.append(s)
        opvals.append(
            ops.get_order_parameters(
                neighcent,
                len(neighcent) - 1,
                indeces_neighs=[j for j in range(len(neighcent) - 1)]))
        if convert_none_to_zero:
            for j, opval in enumerate(opvals[i]):
                if opval is None:
                    opvals[i][j] = 0.0
    return opvals
Beispiel #4
0
def get_order_parameters(struct, pneighs=None, convert_none_to_zero=True):
    """
    Calculate all order parameters (OPs) for all sites in Structure object
    struct.

    Args:
        struct (Structure): input structure.
        pneighs (dict): specification and parameters of
                neighbor-finding approach (see
                get_neighbors_of_site_with_index function
                for more details).
        convert_none_to_zero (bool): flag indicating whether or not
                to convert None values in OPs to zero.

    Returns: ([[float]]) matrix of all sites' (1st dimension)
            order parameters (2nd dimension). 46 order parameters are
            computed per site: q_cn (coordination number), q_lin,
            35 x q_bent (starting with a target angle of 5 degrees and,
            increasing by 5 degrees, until 175 degrees), q_tet, q_oct,
            q_bcc, q_2, q_4, q_6, q_reg_tri, q_sq, q_sq_pyr.
    """
    opvals = []
    optypes = ["cn", "lin"]
    opparas = [[], []]
    for i in range(5, 180, 5):
        optypes.append("bent")
        opparas.append([float(i), 0.0667])
    for t in ["tet", "oct", "bcc", "q2", "q4", "q6", "reg_tri", "sq", \
            "sq_pyr"]: # , "tri_bipyr"]:
        optypes.append(t)
        opparas.append([])
    ops = OrderParameters(optypes, opparas, 100.0)
    for i, s in enumerate(struct.sites):
        neighcent = get_neighbors_of_site_with_index(struct, i, pneighs)
        neighcent.append(s)
        opvals.append(
            ops.get_order_parameters(
                neighcent,
                len(neighcent) - 1,
                indeces_neighs=[j for j in range(len(neighcent) - 1)]))
        if convert_none_to_zero:
            for j, opval in enumerate(opvals[i]):
                if opval is None:
                    opvals[i][j] = 0.0
    return opvals
Beispiel #5
0
    def __init__(self,
                 optypes,
                 override_cn1=True,
                 cutoff_radius=8,
                 tol=1E-2,
                 cation_anion=False):
        """
        Initialize the CrystalSiteFingerprint. Use the from_preset() function to
        use default params.

        Args:
            optypes (dict): a dict of coordination number (int) to a list of str
                representing the order parameter types
            override_cn1 (bool): whether to use a special function for the single
                neighbor case. Suggest to keep True.
            cutoff_radius (int): radius in Angstroms for neighbor finding
            tol (float): numerical tolerance (in case your site distances are
                not perfect or to correct for float tolerances)
            cation_anion (bool): whether to only consider cation<->anion bonds
                (bonds with zero charge are also allowed)
        """

        self.optypes = optypes.copy()
        self.override_cn1 = override_cn1
        self.cutoff_radius = cutoff_radius
        self.tol = tol
        self.cation_anion = cation_anion

        if self.override_cn1 and self.optypes.get(1) != ["wt"]:
            raise ValueError(
                "If override_cn1 is True, optypes[1] must be ['wt']!")

        self.ops = {}
        for cn, t_list in self.optypes.items():
            self.ops[cn] = []
            for t in t_list:
                if t == "wt":
                    self.ops[cn].append(t)

                elif t[:4] == 'bent':
                    self.ops[cn].append(OrderParameters(
                        [t[:4]], parameters=[{'TA': float(t[4:]) / 180.0, \
                                              'IGW_TA': 1.0 / 0.0667}]))
                else:
                    self.ops[cn].append(OrderParameters([t]))
Beispiel #6
0
    def featurize(self, s):
        """
        Calculate all sites' local structure order parameters (LSOPs).

        Args:
            s: Pymatgen Structure object.

            Returns:
                opvals: (2D array of floats) LSOP values of all sites'
                (1st dimension) order parameters (2nd dimension). 46 order
                parameters are computed per site: q_cn (coordination
                number), q_lin, 35 x q_bent (starting with a target angle
                of 5 degrees and, increasing by 5 degrees, until 175 degrees),
                q_tet, q_oct, q_bcc, q_2, q_4, q_6, q_reg_tri, q_sq, q_sq_pyr.
        """
        ops = OrderParameters(self._types, self._paras, 100.0)
        opvals = [[] for t in self._types]
        for i, site in enumerate(s.sites):
            neighcent = get_neighbors_of_site_with_index(
                s, i, p=self.pneighs)
            neighcent.append(site)
            opvalstmp = ops.get_order_parameters(
                neighcent, len(neighcent) - 1,
                indeces_neighs=[j for j in range(len(neighcent) - 1)])
            for j, opval in enumerate(opvalstmp):
                if opval is None:
                    opvals[j].append(0.0)
                else:
                    opvals[j].append(opval)

        if self.stats:
            opstats = []
            for op in opvals:
                if '_mode' in ''.join(self.stats):
                    modes = PropertyStats().n_numerical_modes(
                            op, self.nmodes, 0.01)
                for stat in self.stats:
                    if '_mode' in stat:
                        opstats.append(modes[int(stat[0])-1])
                    else:
                        opstats.append(PropertyStats().calc_stat(op, stat))

            return opstats
        else:
            return opvals
def get_ordering_for_sites(struct, sites):
    """
    Gets the ordering parameter for a list of indices.
    :param struct: Pymatgen Structure object
    :param sites: List of sites for which we want the order parameter.
    :return: Dictionary mapping ordering params to indices.
    """
    bop_types = ["q4"]
    paras = [[]]
    cut_r = 3.0
    # results = {}
    results = []
    bops = OrderParameters(bop_types, paras, cutoff=cut_r)
    for i, s in enumerate(sites):
        op = bops.get_order_parameters(struct, s)
        if op[0] is not None:
            results.append(op[0])
    return np.array(results)
Beispiel #8
0
def get_order_parameters(struct, pneighs=None, convert_none_to_zero=True):
    """
    Calculate all order parameters (OPs) for all sites in Structure object
    struct.

    Args:
        struct (Structure): input structure.
        pneighs (dict): specification and parameters of
                neighbor-finding approach (see
                get_neighbors_of_site_with_index function
                for more details).
        convert_none_to_zero (bool): flag indicating whether or not
                to convert None values in OPs to zero.

    Returns: ([[float]]) matrix of all sites' (1st dimension)
            order parameters (2nd dimension). 46 order parameters are
            computed per site: q_cn (coordination number), q_lin,
            35 x q_bent (starting with a target angle of 5 degrees and,
            increasing by 5 degrees, until 175 degrees), q_tet, q_oct,
            q_bcc, q_2, q_4, q_6, q_reg_tri, q_sq, q_sq_pyr.
    """
    opvals = []
    optypes = ["cn", "lin"]
    opparas = [[], []]
    for i in range(5, 180, 5):
        optypes.append("bent")
        opparas.append([float(i), 0.0667])
    for t in ["tet", "oct", "bcc", "q2", "q4", "q6", "reg_tri", "sq", "sq_pyr"]:  # , "tri_bipyr"]:
        optypes.append(t)
        opparas.append([])
    ops = OrderParameters(optypes, opparas, 100.0)
    for i, s in enumerate(struct.sites):
        neighcent = get_neighbors_of_site_with_index(struct, i, pneighs)
        neighcent.append(s)
        opvals.append(ops.get_order_parameters(
            neighcent, len(neighcent) - 1,
            indeces_neighs=[j for j in range(len(neighcent) - 1)]))
        if convert_none_to_zero:
            for j, opval in enumerate(opvals[i]):
                if opval is None:
                    opvals[i][j] = 0.0
    return opvals
Beispiel #9
0
 def __init__(self,
              optypes=None,
              dr=0.1,
              ddr=0.01,
              ndr=1,
              dop=0.001,
              dist_exp=2,
              zero_ops=True):
     self.optypes = {
         1: ["sgl_bd"],
         2: ["bent180", "bent45", "bent90", "bent135"],
         3: ["tri_plan", "tet", "T"],
         4: ["sq_plan", "sq", "tet", "see_saw", "tri_pyr"],
         5: ["pent_plan", "sq_pyr", "tri_bipyr"],
         6: ["oct", "pent_pyr"],
         7: ["hex_pyr", "pent_bipyr"],
         8: ["bcc", "hex_bipyr"],
         9: ["q2", "q4", "q6"],
         10: ["q2", "q4", "q6"],
         11: ["q2", "q4", "q6"],
         12: ["cuboct", "q2", "q4", "q6"]} if optypes is None \
         else optypes.copy()
     self.dr = dr
     self.ddr = ddr
     self.ndr = ndr
     self.dop = dop
     self.dist_exp = dist_exp
     self.zero_ops = zero_ops
     self.ops = {}
     for cn, t_list in self.optypes.items():
         self.ops[cn] = []
         for t in t_list:
             if t[:4] == 'bent':
                 self.ops[cn].append(OrderParameters(
                     [t[:4]], parameters=[{'TA': float(t[4:]) / 180.0, \
                                           'IGW_TA': 1.0 / 0.0667}]))
             else:
                 self.ops[cn].append(OrderParameters([t]))
Beispiel #10
0
 def test_init(self):
     self.assertIsNotNone(OrderParameters(["cn"], [[]], 0.99))
    def test_get_order_parameters(self):
        # Set up everything.
        op_types = ["cn", "bent", "bent", "tet", "oct", "bcc", "q2", "q4", \
            "q6", "reg_tri", "sq", "sq_pyr_legacy", "tri_bipyr", "sgl_bd", \
            "tri_plan", "sq_plan", "pent_plan", "sq_pyr", "tri_pyr", \
            "pent_pyr", "hex_pyr", "pent_bipyr", "hex_bipyr", "T", "cuboct", \
            "see_saw"]
        op_paras = [None, {'TA': 1, 'IGW_TA': 1./0.0667}, \
                    {'TA': 45./180, 'IGW_TA': 1./0.0667}, None, \
                    None, None, None, None, None, None, None, None, None, \
                    None, None, None, None, None, None, None, None, None, \
                    None, None, None, None]
        ops_044 = OrderParameters(op_types, parameters=op_paras, cutoff=0.44)
        ops_071 = OrderParameters(op_types, parameters=op_paras, cutoff=0.71)
        ops_087 = OrderParameters(op_types, parameters=op_paras, cutoff=0.87)
        ops_099 = OrderParameters(op_types, parameters=op_paras, cutoff=0.99)
        ops_101 = OrderParameters(op_types, parameters=op_paras, cutoff=1.01)
        ops_501 = OrderParameters(op_types, parameters=op_paras, cutoff=5.01)
        ops_voro = OrderParameters(op_types, parameters=op_paras)

        # Single bond.
        op_vals = ops_101.get_order_parameters(self.single_bond, 0)
        self.assertAlmostEqual(int(op_vals[13] * 1000), 1000)
        op_vals = ops_501.get_order_parameters(self.single_bond, 0)
        self.assertAlmostEqual(int(op_vals[13] * 1000), 799)
        op_vals = ops_101.get_order_parameters(self.linear, 0)
        self.assertAlmostEqual(int(op_vals[13] * 1000), 0)

        # Linear motif.
        op_vals = ops_101.get_order_parameters(self.linear, 0)
        self.assertAlmostEqual(int(op_vals[1] * 1000), 1000)

        # 45 degrees-bent motif.
        op_vals = ops_101.get_order_parameters(self.bent45, 0)
        self.assertAlmostEqual(int(op_vals[2] * 1000), 1000)

        # T-shape motif.
        op_vals = ops_101.get_order_parameters(
            self.T_shape, 0, indices_neighs=[1,2,3])
        self.assertAlmostEqual(int(op_vals[23] * 1000), 1000)

        # Cubic structure.
        op_vals = ops_099.get_order_parameters(self.cubic, 0)
        self.assertAlmostEqual(op_vals[0], 0.0)
        self.assertIsNone(op_vals[3])
        self.assertIsNone(op_vals[4])
        self.assertIsNone(op_vals[5])
        self.assertIsNone(op_vals[6])
        self.assertIsNone(op_vals[7])
        self.assertIsNone(op_vals[8])
        op_vals = ops_101.get_order_parameters(self.cubic, 0)
        self.assertAlmostEqual(op_vals[0], 6.0)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 23)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 1000)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 333)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[7] * 1000), 763)
        self.assertAlmostEqual(int(op_vals[8] * 1000), 353)

        # Bcc structure.
        op_vals = ops_087.get_order_parameters(self.bcc, 0)
        self.assertAlmostEqual(op_vals[0], 8.0)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 200)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 145)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 975)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[7] * 1000), 509)
        self.assertAlmostEqual(int(op_vals[8] * 1000), 628)

        # Fcc structure.
        op_vals = ops_071.get_order_parameters(self.fcc, 0)
        self.assertAlmostEqual(op_vals[0], 12.0)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 36)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 78)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[7] * 1000), 190)
        self.assertAlmostEqual(int(op_vals[8] * 1000), 574)

        # Hcp structure.
        op_vals = ops_101.get_order_parameters(self.hcp, 0)
        self.assertAlmostEqual(op_vals[0], 12.0)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 33)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 82)
        self.assertAlmostEqual(int(op_vals[5] * 1000), -38)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[7] * 1000), 97)
        self.assertAlmostEqual(int(op_vals[8] * 1000), 484)

        # Diamond structure.
        op_vals = ops_044.get_order_parameters(self.diamond, 0)
        self.assertAlmostEqual(op_vals[0], 4.0)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 1000)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 37)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 727)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[7] * 1000), 509)
        self.assertAlmostEqual(int(op_vals[8] * 1000), 628)

        # Trigonal off-plane molecule.
        op_vals = ops_044.get_order_parameters(self.trigonal_off_plane, 0)
        self.assertAlmostEqual(op_vals[0], 3.0)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 1000)

        # Trigonal-planar motif.
        op_vals = ops_101.get_order_parameters(self.trigonal_planar, 0)
        self.assertEqual(int(op_vals[0] + 0.5), 3)
        self.assertAlmostEqual(int(op_vals[14] * 1000 + 0.5), 1000)

        # Regular triangle motif.
        op_vals = ops_101.get_order_parameters(self.regular_triangle, 0)
        self.assertAlmostEqual(int(op_vals[9] * 1000), 999)

        # Square-planar motif.
        op_vals = ops_101.get_order_parameters(self.square_planar, 0)
        self.assertAlmostEqual(int(op_vals[15] * 1000 + 0.5), 1000)

        # Square motif.
        op_vals = ops_101.get_order_parameters(self.square, 0)
        self.assertAlmostEqual(int(op_vals[10] * 1000), 1000)

        # Pentagonal planar.
        op_vals = ops_101.get_order_parameters(
                self.pentagonal_planar.sites, 0, indices_neighs=[1,2,3,4,5])
        self.assertAlmostEqual(int(op_vals[12] * 1000 + 0.5), 33)
        self.assertAlmostEqual(int(op_vals[16] * 1000 + 0.5), 1000)

        # Trigonal pyramid motif.
        op_vals = ops_101.get_order_parameters(
            self.trigonal_pyramid, 0, indices_neighs=[1,2,3,4])
        self.assertAlmostEqual(int(op_vals[18] * 1000 + 0.5), 1000)

        # Square pyramid motif.
        op_vals = ops_101.get_order_parameters(self.square_pyramid, 0)
        self.assertAlmostEqual(int(op_vals[11] * 1000 + 0.5), 1000)
        self.assertAlmostEqual(int(op_vals[12] * 1000 + 0.5), 375)
        self.assertAlmostEqual(int(op_vals[17] * 1000 + 0.5), 1000)

        # Pentagonal pyramid motif.
        op_vals = ops_101.get_order_parameters(
            self.pentagonal_pyramid, 0, indices_neighs=[1,2,3,4,5,6])
        self.assertAlmostEqual(int(op_vals[19] * 1000 + 0.5), 1000)

        # Hexagonal pyramid motif.
        op_vals = ops_101.get_order_parameters(
            self.hexagonal_pyramid, 0, indices_neighs=[1,2,3,4,5,6,7])
        self.assertAlmostEqual(int(op_vals[20] * 1000 + 0.5), 1000)

        # Trigonal bipyramidal.
        op_vals = ops_101.get_order_parameters(
            self.trigonal_bipyramidal.sites, 0, indices_neighs=[1,2,3,4,5])
        self.assertAlmostEqual(int(op_vals[12] * 1000 + 0.5), 1000)

        # Pentagonal bipyramidal.
        op_vals = ops_101.get_order_parameters(
            self.pentagonal_bipyramid.sites, 0,
            indices_neighs=[1,2,3,4,5,6,7])
        self.assertAlmostEqual(int(op_vals[21] * 1000 + 0.5), 1000)

        # Hexagonal bipyramid motif.
        op_vals = ops_101.get_order_parameters(
            self.hexagonal_bipyramid, 0, indices_neighs=[1,2,3,4,5,6,7,8])
        self.assertAlmostEqual(int(op_vals[22] * 1000 + 0.5), 1000)

        # Cuboctahedral motif.
        op_vals = ops_101.get_order_parameters(
            self.cuboctahedron, 0, indices_neighs=[i for i in range(1, 13)])
        self.assertAlmostEqual(int(op_vals[24] * 1000 + 0.5), 1000)

        # See-saw motif.
        op_vals = ops_101.get_order_parameters(
            self.see_saw, 0, indices_neighs=[i for i in range(1, 5)])
        self.assertAlmostEqual(int(op_vals[25] * 1000 + 0.5), 1000)

        # Test providing explicit neighbor lists.
        op_vals = ops_101.get_order_parameters(self.bcc, 0, indices_neighs=[1])
        self.assertIsNotNone(op_vals[0])
        self.assertIsNone(op_vals[3])
        with self.assertRaises(ValueError):
            ops_101.get_order_parameters(self.bcc, 0, indices_neighs=[2])
 def test_init(self):
     self.assertIsNotNone(
         OrderParameters(["cn"], parameters=None, cutoff=0.99))
    def test_get_order_parameters(self):
        # Set up everything.
        op_types = ["cn", "tet", "oct", "bcc", "q2", "q4", "q6"]
        op_paras = [[], [], [], [], [], [], []]
        ops_044 = OrderParameters(op_types, op_paras, 0.44)
        ops_071 = OrderParameters(op_types, op_paras, 0.71)
        ops_087 = OrderParameters(op_types, op_paras, 0.87)
        ops_099 = OrderParameters(op_types, op_paras, 0.99)
        ops_101 = OrderParameters(op_types, op_paras, 1.01)
        ops_voro = OrderParameters(op_types, op_paras)

        # Cubic structure.
        op_vals = ops_099.get_order_parameters(self.cubic, 0)
        self.assertAlmostEqual(op_vals[0], 0.0)
        self.assertIsNone(op_vals[1])
        self.assertIsNone(op_vals[2])
        self.assertIsNone(op_vals[3])
        self.assertIsNone(op_vals[4])
        self.assertIsNone(op_vals[5])
        self.assertIsNone(op_vals[6])
        op_vals = ops_101.get_order_parameters(self.cubic, 0)
        self.assertAlmostEqual(op_vals[0], 6.0)
        self.assertAlmostEqual(int(op_vals[1] * 1000), -72)
        self.assertAlmostEqual(int(op_vals[2] * 1000), 1000)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 125)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 763)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 353)

        # Bcc structure.
        op_vals = ops_087.get_order_parameters(self.bcc, 0)
        self.assertAlmostEqual(op_vals[0], 8.0)
        self.assertAlmostEqual(int(op_vals[1] * 1000),
                               1968)  # 1.9688949183589557
        self.assertAlmostEqual(int(op_vals[2] * 1000),
                               125)  # 0.12540815310925768
        self.assertAlmostEqual(int(op_vals[3] * 1000),
                               975)  # 0.9753713330608598
        self.assertAlmostEqual(int(op_vals[4] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[5] * 1000),
                               509)  # 0.5091750772173156
        self.assertAlmostEqual(int(op_vals[6] * 1000),
                               628)  # 0.6285393610547088

        # Fcc structure.
        op_vals = ops_071.get_order_parameters(self.fcc, 0)
        self.assertAlmostEqual(op_vals[0], 12.0)
        self.assertAlmostEqual(int(op_vals[1] * 1000),
                               -998)  # -0.9989621462333275
        self.assertAlmostEqual(int(op_vals[2] * 1000),
                               -1012)  # -1.0125484381377454
        self.assertAlmostEqual(int(op_vals[3] * 1000),
                               0)  # -0.0007417813723164877
        self.assertAlmostEqual(int(op_vals[4] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[5] * 1000),
                               190)  # 0.1909406539564932
        self.assertAlmostEqual(int(op_vals[6] * 1000), 574)  # 0.57452425971407

        # Hcp structure.
        op_vals = ops_101.get_order_parameters(self.hcp, 0)
        self.assertAlmostEqual(op_vals[0], 12.0)
        self.assertAlmostEqual(int(op_vals[1] * 1000), -455)
        self.assertAlmostEqual(int(op_vals[2] * 1000), -735)
        self.assertAlmostEqual(int(op_vals[3] * 1000), -155)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 97)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 484)

        # Diamond structure.
        op_vals = ops_044.get_order_parameters(self.diamond, 0)
        self.assertAlmostEqual(op_vals[0], 4.0)
        self.assertAlmostEqual(int(op_vals[1] * 1000), 1000)
        self.assertAlmostEqual(int(op_vals[2] * 1000), -8)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 80)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 509)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 628)

        # Test providing explicit neighbor lists.
        op_vals = ops_101.get_order_parameters(self.bcc, 0, indeces_neighs=[1])
        self.assertIsNotNone(op_vals[0])
        self.assertIsNone(op_vals[1])
        with self.assertRaises(ValueError):
            ops_101.get_order_parameters(self.bcc, 0, indeces_neighs=[2])
    def test_get_order_parameters(self):
        # Set up everything.
        op_types = ["cn", "tet", "oct", "bcc", "q2", "q4", "q6"]
        op_paras = [[], [], [], [], [], [], []]
        ops_044 = OrderParameters(op_types, op_paras, 0.44)
        ops_071 = OrderParameters(op_types, op_paras, 0.71)
        ops_087 = OrderParameters(op_types, op_paras, 0.87)
        ops_099 = OrderParameters(op_types, op_paras, 0.99)
        ops_101 = OrderParameters(op_types, op_paras, 1.01)
        ops_voro = OrderParameters(op_types, op_paras)

        # Cubic structure.
        op_vals = ops_099.get_order_parameters(self.cubic, 0)
        self.assertAlmostEqual(op_vals[0], 0.0)
        self.assertIsNone(op_vals[1])
        self.assertIsNone(op_vals[2])
        self.assertIsNone(op_vals[3])
        self.assertIsNone(op_vals[4])
        self.assertIsNone(op_vals[5])
        self.assertIsNone(op_vals[6])
        op_vals = ops_101.get_order_parameters(self.cubic, 0)
        self.assertAlmostEqual(op_vals[0], 6.0)
        self.assertAlmostEqual(int(op_vals[1] * 1000), -72)
        self.assertAlmostEqual(int(op_vals[2] * 1000), 1000)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 125)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 763)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 353)

        # Bcc structure.
        op_vals = ops_087.get_order_parameters(self.bcc, 0)
        self.assertAlmostEqual(op_vals[0], 8.0)
        self.assertAlmostEqual(int(op_vals[1] * 1000),
                               1968)  # 1.9688949183589557
        self.assertAlmostEqual(int(op_vals[2] * 1000),
                               125)  # 0.12540815310925768
        self.assertAlmostEqual(int(op_vals[3] * 1000),
                               975)  # 0.9753713330608598
        self.assertAlmostEqual(int(op_vals[4] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[5] * 1000),
                               509)  # 0.5091750772173156
        self.assertAlmostEqual(int(op_vals[6] * 1000),
                               628)  # 0.6285393610547088

        # Fcc structure.
        op_vals = ops_071.get_order_parameters(self.fcc, 0)
        self.assertAlmostEqual(op_vals[0], 12.0)
        self.assertAlmostEqual(int(op_vals[1] * 1000),
                               -998)  # -0.9989621462333275
        self.assertAlmostEqual(int(op_vals[2] * 1000),
                               -1012)  # -1.0125484381377454
        self.assertAlmostEqual(int(op_vals[3] * 1000),
                               0)  # -0.0007417813723164877
        self.assertAlmostEqual(int(op_vals[4] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[5] * 1000),
                               190)  # 0.1909406539564932
        self.assertAlmostEqual(int(op_vals[6] * 1000), 574)  # 0.57452425971407

        # Hcp structure.
        op_vals = ops_101.get_order_parameters(self.hcp, 0)
        self.assertAlmostEqual(op_vals[0], 12.0)
        self.assertAlmostEqual(int(op_vals[1] * 1000), -455)
        self.assertAlmostEqual(int(op_vals[2] * 1000), -735)
        self.assertAlmostEqual(int(op_vals[3] * 1000), -155)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 97)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 484)

        # Diamond structure.
        op_vals = ops_044.get_order_parameters(self.diamond, 0)
        self.assertAlmostEqual(op_vals[0], 4.0)
        self.assertAlmostEqual(int(op_vals[1] * 1000), 1000)
        self.assertAlmostEqual(int(op_vals[2] * 1000), -8)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 80)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 509)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 628)

        # Test providing explicit neighbor lists.
        op_vals = ops_101.get_order_parameters(self.bcc, 0, indeces_neighs=[1])
        self.assertIsNotNone(op_vals[0])
        self.assertIsNone(op_vals[1])
        with self.assertRaises(ValueError):
            ops_101.get_order_parameters(self.bcc, 0, indeces_neighs=[2])
Beispiel #15
0
def site_is_of_motif_type(struct, n, approach="min_dist", delta=0.1, \
        cutoff=10.0, thresh=None):
    """
    Returns the motif type of the site with index n in structure struct;
    currently featuring "tetrahedral", "octahedral", "bcc", and "cp"
    (close-packed: fcc and hcp) as well as "square pyramidal" and
    "trigonal bipyramidal".  If the site is not recognized,
    "unrecognized" is returned.  If a site should be assigned to two
    different motifs, "multiple assignments" is returned.

    Args:
        struct (Structure): input structure.
        n (int): index of site in Structure object for which motif type
                is to be determined.
        approach (str): type of neighbor-finding approach, where
              "min_dist" will use the MinimumDistanceNN class,
              "voronoi" the VoronoiNN class, "min_OKeeffe" the
              MinimumOKeeffe class, and "min_VIRE" the MinimumVIRENN class.
        delta (float): tolerance involved in neighbor finding.
        cutoff (float): (large) radius to find tentative neighbors.
        thresh (dict): thresholds for motif criteria (currently, required
                keys and their default values are "qtet": 0.5,
                "qoct": 0.5, "qbcc": 0.5, "q6": 0.4).

    Returns: motif type (str).
    """

    if thresh is None:
        thresh = {
            "qtet": 0.5, "qoct": 0.5, "qbcc": 0.5, "q6": 0.4,
            "qtribipyr": 0.8, "qsqpyr": 0.8}

    ops = OrderParameters([
            "cn", "tet", "oct", "bcc", "q6", "sq_pyr", "tri_bipyr"])

    neighs_cent = get_neighbors_of_site_with_index(
            struct, n, approach=approach, delta=delta, cutoff=cutoff)
    neighs_cent.append(struct.sites[n])
    opvals = ops.get_order_parameters(
            neighs_cent, len(neighs_cent)-1, indices_neighs=[
            i for i in range(len(neighs_cent)-1)])
    cn = int(opvals[0] + 0.5)
    motif_type = "unrecognized"
    nmotif = 0

    if cn == 4 and opvals[1] > thresh["qtet"]:
        motif_type = "tetrahedral"
        nmotif += 1
    if cn == 5 and opvals[5] > thresh["qsqpyr"]:
       motif_type = "square pyramidal"
       nmotif += 1
    if cn == 5 and opvals[6] > thresh["qtribipyr"]:
       motif_type = "trigonal bipyramidal"
       nmotif += 1
    if cn == 6 and opvals[2] > thresh["qoct"]:
        motif_type = "octahedral"
        nmotif += 1
    if cn == 8 and (opvals[3] > thresh["qbcc"] and opvals[1] < thresh["qtet"]):
        motif_type = "bcc"
        nmotif += 1
    if cn == 12 and (opvals[4] > thresh["q6"] and opvals[1] < thresh["q6"] and \
                                 opvals[2] < thresh["q6"] and opvals[3] < thresh["q6"]):
        motif_type = "cp"
        nmotif += 1

    if nmotif > 1:
        motif_type = "multiple assignments"

    return motif_type
Beispiel #16
0
    def test_get_order_parameters(self):
        # Set up everything.
        op_types = ["cn", "lin", "bent", "tet", "oct", "bcc", "q2", "q4", \
                "q6", "reg_tri", "sq", "sq_pyr", "tri_bipyr"]
        op_paras = [[], [], [], [], [], [], [], [], [], [], [], [], []]
        op_paras = [[], [], [45.0, 0.0667], [], [], [], [], [], [], [], [], [],
                    []]
        ops_044 = OrderParameters(op_types, op_paras, 0.44)
        ops_071 = OrderParameters(op_types, op_paras, 0.71)
        ops_087 = OrderParameters(op_types, op_paras, 0.87)
        ops_099 = OrderParameters(op_types, op_paras, 0.99)
        ops_101 = OrderParameters(op_types, op_paras, 1.01)
        ops_voro = OrderParameters(op_types, op_paras)

        # Linear motif.
        op_vals = ops_101.get_order_parameters(self.linear, 0)
        self.assertAlmostEqual(int(op_vals[1] * 1000), 1000)

        # 45 degrees-bent motif.
        op_vals = ops_101.get_order_parameters(self.bent45, 0)
        self.assertAlmostEqual(int(op_vals[2] * 1000), 1000)

        # Cubic structure.
        op_vals = ops_099.get_order_parameters(self.cubic, 0)
        self.assertAlmostEqual(op_vals[0], 0.0)
        self.assertIsNone(op_vals[3])
        self.assertIsNone(op_vals[4])
        self.assertIsNone(op_vals[5])
        self.assertIsNone(op_vals[6])
        self.assertIsNone(op_vals[7])
        self.assertIsNone(op_vals[8])
        op_vals = ops_101.get_order_parameters(self.cubic, 0)
        self.assertAlmostEqual(op_vals[0], 6.0)
        self.assertAlmostEqual(int(op_vals[3] * 1000), -14)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 1000)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 333)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[7] * 1000), 763)
        self.assertAlmostEqual(int(op_vals[8] * 1000), 353)

        # Bcc structure.
        op_vals = ops_087.get_order_parameters(self.bcc, 0)
        self.assertAlmostEqual(op_vals[0], 8.0)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 140)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 42)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 975)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[7] * 1000), 509)
        self.assertAlmostEqual(int(op_vals[8] * 1000), 628)

        # Fcc structure.
        op_vals = ops_071.get_order_parameters(self.fcc, 0)
        self.assertAlmostEqual(op_vals[0], 12.0)
        self.assertAlmostEqual(int(op_vals[3] * 1000), -18)
        self.assertAlmostEqual(int(op_vals[4] * 1000), -81)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[7] * 1000), 190)
        self.assertAlmostEqual(int(op_vals[8] * 1000), 574)

        # Hcp structure.
        op_vals = ops_101.get_order_parameters(self.hcp, 0)
        self.assertAlmostEqual(op_vals[0], 12.0)
        self.assertAlmostEqual(int(op_vals[3] * 1000), -8)
        self.assertAlmostEqual(int(op_vals[4] * 1000), -59)
        self.assertAlmostEqual(int(op_vals[5] * 1000), -38)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[7] * 1000), 97)
        self.assertAlmostEqual(int(op_vals[8] * 1000), 484)

        # Diamond structure.
        op_vals = ops_044.get_order_parameters(self.diamond, 0)
        self.assertAlmostEqual(op_vals[0], 4.0)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 1000)
        self.assertAlmostEqual(int(op_vals[4] * 1000), -39)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 727)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[7] * 1000), 509)
        self.assertAlmostEqual(int(op_vals[8] * 1000), 628)

        # Regular triangle motif.
        op_vals = ops_101.get_order_parameters(self.regular_triangle, 0)
        self.assertAlmostEqual(int(op_vals[9] * 1000), 999)

        # Square motif.
        op_vals = ops_101.get_order_parameters(self.square, 0)
        self.assertAlmostEqual(int(op_vals[10] * 1000), 1000)

        # Pentagonal planar.
        op_vals = ops_101.get_order_parameters(self.pentagonal_planar.sites,
                                               0,
                                               indeces_neighs=[1, 2, 3, 4, 5])
        self.assertAlmostEqual(int(op_vals[12] * 1000), 100)

        # Square pyramid motif.
        op_vals = ops_101.get_order_parameters(self.square_pyramid, 0)
        self.assertAlmostEqual(int(op_vals[11] * 1000 + 0.5), 1000)
        self.assertAlmostEqual(int(op_vals[12] * 1000 + 0.5), 500)

        # Trigonal bipyramidal.
        op_vals = ops_101.get_order_parameters(self.trigonal_bipyramidal.sites,
                                               0,
                                               indeces_neighs=[1, 2, 3, 4, 5])
        self.assertAlmostEqual(int(op_vals[12] * 1000 + 0.5), 1000)

        # Test providing explicit neighbor lists.
        op_vals = ops_101.get_order_parameters(self.bcc, 0, indeces_neighs=[1])
        self.assertIsNotNone(op_vals[0])
        self.assertIsNone(op_vals[3])
        with self.assertRaises(ValueError):
            ops_101.get_order_parameters(self.bcc, 0, indeces_neighs=[2])
Beispiel #17
0
def site_is_of_motif_type(struct, n, approach="min_dist", delta=0.1, \
        cutoff=10.0, thresh=None):
    """
    Returns the motif type of the site with index n in structure struct;
    currently featuring "tetrahedral", "octahedral", "bcc", and "cp"
    (close-packed: fcc and hcp) as well as "square pyramidal" and
    "trigonal bipyramidal".  If the site is not recognized,
    "unrecognized" is returned.  If a site should be assigned to two
    different motifs, "multiple assignments" is returned.

    Args:
        struct (Structure): input structure.
        n (int): index of site in Structure object for which motif type
                is to be determined.
        approach (str): type of neighbor-finding approach, where
              "min_dist" will use the MinimumDistanceNN class,
              "voronoi" the VoronoiNN class, "min_OKeeffe" the
              MinimumOKeeffe class, and "min_VIRE" the MinimumVIRENN class.
        delta (float): tolerance involved in neighbor finding.
        cutoff (float): (large) radius to find tentative neighbors.
        thresh (dict): thresholds for motif criteria (currently, required
                keys and their default values are "qtet": 0.5,
                "qoct": 0.5, "qbcc": 0.5, "q6": 0.4).

    Returns: motif type (str).
    """

    if thresh is None:
        thresh = {
            "qtet": 0.5, "qoct": 0.5, "qbcc": 0.5, "q6": 0.4,
            "qtribipyr": 0.8, "qsqpyr": 0.8}

    ops = OrderParameters([
            "cn", "tet", "oct", "bcc", "q6", "sq_pyr", "tri_bipyr"])

    neighs_cent = get_neighbors_of_site_with_index(
            struct, n, approach=approach, delta=delta, cutoff=cutoff)
    neighs_cent.append(struct.sites[n])
    opvals = ops.get_order_parameters(
            neighs_cent, len(neighs_cent)-1, indeces_neighs=[
            i for i in range(len(neighs_cent)-1)])
    cn = int(opvals[0] + 0.5)
    motif_type = "unrecognized"
    nmotif = 0

    if cn == 4 and opvals[1] > thresh["qtet"]:
        motif_type = "tetrahedral"
        nmotif += 1
    if cn == 5 and opvals[5] > thresh["qsqpyr"]:
       motif_type = "square pyramidal"
       nmotif += 1
    if cn == 5 and opvals[6] > thresh["qtribipyr"]:
       motif_type = "trigonal bipyramidal"
       nmotif += 1
    if cn == 6 and opvals[2] > thresh["qoct"]:
        motif_type = "octahedral"
        nmotif += 1
    if cn == 8 and (opvals[3] > thresh["qbcc"] and opvals[1] < thresh["qtet"]):
        motif_type = "bcc"
        nmotif += 1
    if cn == 12 and (opvals[4] > thresh["q6"] and opvals[1] < thresh["q6"] and \
                                 opvals[2] < thresh["q6"] and opvals[3] < thresh["q6"]):
        motif_type = "cp"
        nmotif += 1

    if nmotif > 1:
        motif_type = "multiple assignments"

    return motif_type
    def test_get_order_parameters(self):
        # Set up everything.
        op_types = ["cn", "lin", "bent", "tet", "oct", "bcc", "q2", "q4", \
                "q6", "reg_tri", "sq", "sq_pyr", "tri_bipyr"]
        op_paras = [[], [], [], [], [], [], [], [], [], [], [], [], []]
        op_paras = [[], [], [45.0, 0.0667], [], [], [], [], [], [], [], [], [], []]
        ops_044 = OrderParameters(op_types, op_paras, 0.44)
        ops_071 = OrderParameters(op_types, op_paras, 0.71)
        ops_087 = OrderParameters(op_types, op_paras, 0.87)
        ops_099 = OrderParameters(op_types, op_paras, 0.99)
        ops_101 = OrderParameters(op_types, op_paras, 1.01)
        ops_voro = OrderParameters(op_types, op_paras)

        # Linear motif.
        op_vals = ops_101.get_order_parameters(self.linear, 0)
        self.assertAlmostEqual(int(op_vals[1] * 1000), 1000)

        # 45 degrees-bent motif.
        op_vals = ops_101.get_order_parameters(self.bent45, 0)
        self.assertAlmostEqual(int(op_vals[2] * 1000), 1000)

        # Cubic structure.
        op_vals = ops_099.get_order_parameters(self.cubic, 0)
        self.assertAlmostEqual(op_vals[0], 0.0)
        self.assertIsNone(op_vals[3])
        self.assertIsNone(op_vals[4])
        self.assertIsNone(op_vals[5])
        self.assertIsNone(op_vals[6])
        self.assertIsNone(op_vals[7])
        self.assertIsNone(op_vals[8])
        op_vals = ops_101.get_order_parameters(self.cubic, 0)
        self.assertAlmostEqual(op_vals[0], 6.0)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 14)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 1000)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 333)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[7] * 1000), 763)
        self.assertAlmostEqual(int(op_vals[8] * 1000), 353)

        # Bcc structure.
        op_vals = ops_087.get_order_parameters(self.bcc, 0)
        self.assertAlmostEqual(op_vals[0], 8.0)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 142)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 145)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 975)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[7] * 1000), 509)
        self.assertAlmostEqual(int(op_vals[8] * 1000), 628)

        # Fcc structure.
        op_vals = ops_071.get_order_parameters(self.fcc, 0)
        self.assertAlmostEqual(op_vals[0], 12.0)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 30)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 78)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[7] * 1000), 190)
        self.assertAlmostEqual(int(op_vals[8] * 1000), 574)

        # Hcp structure.
        op_vals = ops_101.get_order_parameters(self.hcp, 0)
        self.assertAlmostEqual(op_vals[0], 12.0)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 30)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 89)
        self.assertAlmostEqual(int(op_vals[5] * 1000), -38)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[7] * 1000), 97)
        self.assertAlmostEqual(int(op_vals[8] * 1000), 484)

        # Diamond structure.
        op_vals = ops_044.get_order_parameters(self.diamond, 0)
        self.assertAlmostEqual(op_vals[0], 4.0)
        self.assertAlmostEqual(int(op_vals[3] * 1000), 1000)
        self.assertAlmostEqual(int(op_vals[4] * 1000), 45)
        self.assertAlmostEqual(int(op_vals[5] * 1000), 727)
        self.assertAlmostEqual(int(op_vals[6] * 1000), 0)
        self.assertAlmostEqual(int(op_vals[7] * 1000), 509)
        self.assertAlmostEqual(int(op_vals[8] * 1000), 628)

        # Regular triangle motif.
        op_vals = ops_101.get_order_parameters(self.regular_triangle, 0)
        self.assertAlmostEqual(int(op_vals[9] * 1000), 999)

        # Square motif.
        op_vals = ops_101.get_order_parameters(self.square, 0)
        self.assertAlmostEqual(int(op_vals[10] * 1000), 1000)

        # Pentagonal planar.
        op_vals = ops_101.get_order_parameters(
                self.pentagonal_planar.sites, 0, indeces_neighs=[1,2,3,4,5])
        self.assertAlmostEqual(int(op_vals[12] * 1000), 100)

        # Square pyramid motif.
        op_vals = ops_101.get_order_parameters(self.square_pyramid, 0)
        self.assertAlmostEqual(int(op_vals[11] * 1000 + 0.5), 1000)
        self.assertAlmostEqual(int(op_vals[12] * 1000 + 0.5), 500)

        # Trigonal bipyramidal.
        op_vals = ops_101.get_order_parameters(
                self.trigonal_bipyramidal.sites, 0, indeces_neighs=[1,2,3,4,5])
        self.assertAlmostEqual(int(op_vals[12] * 1000 + 0.5), 1000)

        # Test providing explicit neighbor lists.
        op_vals = ops_101.get_order_parameters(self.bcc, 0, indeces_neighs=[1])
        self.assertIsNotNone(op_vals[0])
        self.assertIsNone(op_vals[3])
        with self.assertRaises(ValueError):
            ops_101.get_order_parameters(self.bcc, 0, indeces_neighs=[2])