Beispiel #1
0
    def test_all_nn_classes(self):
        self.assertEqual(MinimumDistanceNN(cutoff=5, get_all_sites=True).get_cn(
            self.cscl, 0), 14)
        self.assertEqual(MinimumDistanceNN().get_cn(self.diamond, 0), 4)
        self.assertEqual(MinimumDistanceNN().get_cn(self.nacl, 0), 6)
        self.assertEqual(MinimumDistanceNN().get_cn(self.lifepo4, 0), 6)
        self.assertEqual(MinimumDistanceNN(tol=0.01).get_cn(self.cscl, 0), 8)
        self.assertEqual(MinimumDistanceNN(tol=0.1).get_cn(self.mos2, 0), 6)

        for image in MinimumDistanceNN(tol=0.1).get_nn_images(self.mos2, 0):
            self.assertTrue(image in [(0, 0, 0), (0, 1, 0), (-1, 0, 0),
                                      (0, 0, 0), (0, 1, 0), (-1, 0, 0)])

        okeeffe = MinimumOKeeffeNN(tol=0.01)
        self.assertEqual(okeeffe.get_cn(self.diamond, 0), 4)
        self.assertEqual(okeeffe.get_cn(self.nacl, 0), 6)
        self.assertEqual(okeeffe.get_cn(self.cscl, 0), 8)
        self.assertEqual(okeeffe.get_cn(self.lifepo4, 0), 2)

        virenn = MinimumVIRENN(tol=0.01)
        self.assertEqual(virenn.get_cn(self.diamond, 0), 4)
        self.assertEqual(virenn.get_cn(self.nacl, 0), 6)
        self.assertEqual(virenn.get_cn(self.cscl, 0), 8)
        self.assertEqual(virenn.get_cn(self.lifepo4, 0), 2)

        brunner_recip = BrunnerNN_reciprocal(tol=0.01)
        self.assertEqual(brunner_recip.get_cn(self.diamond, 0), 4)
        self.assertEqual(brunner_recip.get_cn(self.nacl, 0), 6)
        self.assertEqual(brunner_recip.get_cn(self.cscl, 0), 14)
        self.assertEqual(brunner_recip.get_cn(self.lifepo4, 0), 6)

        brunner_rel = BrunnerNN_relative(tol=0.01)
        self.assertEqual(brunner_rel.get_cn(self.diamond, 0), 4)
        self.assertEqual(brunner_rel.get_cn(self.nacl, 0), 6)
        self.assertEqual(brunner_rel.get_cn(self.cscl, 0), 14)
        self.assertEqual(brunner_rel.get_cn(self.lifepo4, 0), 6)

        brunner_real = BrunnerNN_real(tol=0.01)
        self.assertEqual(brunner_real.get_cn(self.diamond, 0), 4)
        self.assertEqual(brunner_real.get_cn(self.nacl, 0), 6)
        self.assertEqual(brunner_real.get_cn(self.cscl, 0), 14)
        self.assertEqual(brunner_real.get_cn(self.lifepo4, 0), 30)

        econn = EconNN()
        self.assertEqual(econn.get_cn(self.diamond, 0), 4)
        self.assertEqual(econn.get_cn(self.nacl, 0), 6)
        self.assertEqual(econn.get_cn(self.cscl, 0), 14)
        self.assertEqual(econn.get_cn(self.lifepo4, 0), 6)

        voroinn = VoronoiNN(tol=0.5)
        self.assertEqual(voroinn.get_cn(self.diamond, 0), 4)
        self.assertEqual(voroinn.get_cn(self.nacl, 0), 6)
        self.assertEqual(voroinn.get_cn(self.cscl, 0), 8)
        self.assertEqual(voroinn.get_cn(self.lifepo4, 0), 6)

        crystalnn = CrystalNN()
        self.assertEqual(crystalnn.get_cn(self.diamond, 0), 4)
        self.assertEqual(crystalnn.get_cn(self.nacl, 0), 6)
        self.assertEqual(crystalnn.get_cn(self.cscl, 0), 8)
        self.assertEqual(crystalnn.get_cn(self.lifepo4, 0), 6)
Beispiel #2
0
    def get_coordinations(self):
        """
        Inputs
            struct: a pymatgen structure object

        Returns
            coordination_numbers: a dictionary containing each species' name and average coordination
            number rounded to nearest integer
        """
        struct = self.structure
        vnn = CrystalNN()
        coordination_numbers = {}
        stoich = defaultdict(int)
        for site in struct.as_dict()['sites']:
            elem = site['species'][0]['element']
            stoich[elem] += 1
        for spec in stoich.keys():
            coordination_numbers[spec] = 0.0
        for atom in range(len(struct)):
            try:
                cn = vnn.get_cn(struct, atom, use_weights=False)
                coordination_numbers[
                    struct[atom].species.elements[0].element.symbol] += cn
            except:
                return None
        for spec in coordination_numbers:
            coordination_numbers[
                spec] = coordination_numbers[spec] / stoich[spec]
            coordination_numbers[spec] = int(round(coordination_numbers[spec]))

        return coordination_numbers
Beispiel #3
0
    def test_noble_gas_material(self):
        cnn = CrystalNN()

        self.assertEqual(cnn.get_cn(self.he_bcc, 0, use_weights=False), 0)

        cnn = CrystalNN(distance_cutoffs=(1.25, 5))
        self.assertEqual(cnn.get_cn(self.he_bcc, 0, use_weights=False), 8)
Beispiel #4
0
    def setUp(self):
        cnn = CrystalNN()

        mapi = cnn.get_bonded_structure(self.get_structure("mapi"))
        mapi_components = get_structure_components(mapi,
                                                   inc_molecule_graph=True)
        mol_components, _ = filter_molecular_components(mapi_components)
        self.methylammonium = mol_components[0]['molecule_graph']
Beispiel #5
0
    def test_discrete_cn(self):
        cnn = CrystalNN()
        cn_array = []
        expected_array = [6, 6, 6, 6, 6, 6, 6, 6, 4, 4, 4, 4, 4, 4, 4, 4, 4,
                          4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]
        for idx, _ in enumerate(self.lifepo4):
            cn_array.append(cnn.get_cn(self.lifepo4, idx))

        self.assertSequenceEqual(cn_array, expected_array)
Beispiel #6
0
    def test_discrete_cn(self):
        cnn = CrystalNN()
        cn_array = []
        expected_array = [6, 6, 6, 6, 6, 6, 6, 6, 4, 4, 4, 4, 4, 4, 4, 4, 4,
                          4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]
        for idx, _ in enumerate(self.lifepo4):
            cn_array.append(cnn.get_cn(self.lifepo4, idx))

        self.assertSequenceEqual(cn_array, expected_array)
    def test_weighted_cn(self):
        cnn = CrystalNN(weighted_cn=True)
        cn_array = []
        expected_array = [6.0449, 6.0431, 6.0449, 6.0431, 5.6262, 5.6253,
                          5.6258, 5.6258, 3.9936, 3.9936, 3.9936, 3.9936,
                          3.9183, 3.7318, 3.7259, 3.781, 3.781, 3.7259,
                          3.7318, 3.9183, 3.9183, 3.7318, 3.7248, 3.7819,
                          3.7819, 3.7248, 3.7318, 3.9183]
        for idx, _ in enumerate(self.lifepo4):
            cn_array.append(cnn.get_cn(self.lifepo4, idx, use_weights=True))

        self.assertArrayAlmostEqual(expected_array, cn_array, 2)
Beispiel #8
0
    def test_weighted_cn(self):
        cnn = CrystalNN(weighted_cn=True)
        cn_array = []

        expected_array = [5.8962, 5.8996, 5.8962, 5.8996, 5.7195, 5.7195,
                          5.7202, 5.7194, 4.0012, 4.0012, 4.0012, 4.0009,
                          3.3897, 3.2589, 3.1218, 3.1914, 3.1914, 3.1218,
                          3.2589, 3.3897, 3.3897, 3.2589, 3.1207, 3.1924,
                          3.1915, 3.1207, 3.2598, 3.3897]
        for idx, _ in enumerate(self.lifepo4):
            cn_array.append(cnn.get_cn(self.lifepo4, idx, use_weights=True))

        self.assertArrayAlmostEqual(expected_array, cn_array, 2)
Beispiel #9
0
    def test_weighted_cn(self):
        cnn = CrystalNN(weighted_cn=True)
        cn_array = []
        expected_array = [
            6.0449, 6.0431, 6.0449, 6.0431, 5.6262, 5.6253, 5.6258, 5.6258,
            3.9936, 3.9936, 3.9936, 3.9936, 3.9183, 3.7318, 3.7259, 3.781,
            3.781, 3.7259, 3.7318, 3.9183, 3.9183, 3.7318, 3.7248, 3.7819,
            3.7819, 3.7248, 3.7318, 3.9183
        ]
        for idx, _ in enumerate(self.lifepo4):
            cn_array.append(cnn.get_cn(self.lifepo4, idx, use_weights=True))

        self.assertArrayAlmostEqual(expected_array, cn_array, 2)
Beispiel #10
0
    def test_weighted_cn(self):
        cnn = CrystalNN(weighted_cn=True)
        cn_array = []

        expected_array = [5.863, 5.8716, 5.863, 5.8716, 5.7182, 5.7182, 5.719,
                          5.7181, 3.991, 3.991, 3.991, 3.9907, 3.5997, 3.525,
                          3.4133, 3.4714, 3.4727, 3.4133, 3.525, 3.5997,
                          3.5997, 3.525, 3.4122, 3.4738, 3.4728, 3.4109,
                          3.5259, 3.5997]
        for idx, _ in enumerate(self.lifepo4):
            cn_array.append(cnn.get_cn(self.lifepo4, idx, use_weights=True))

        self.assertArrayAlmostEqual(expected_array, cn_array, 2)
Beispiel #11
0
    def test_weighted_cn(self):
        cnn = CrystalNN(weighted_cn=True)
        cn_array = []

        expected_array = [5.863, 5.8716, 5.863 , 5.8716, 5.7182, 5.7182, 5.719,
                          5.7181, 3.991 , 3.991 , 3.991 , 3.9907, 3.5997, 3.525,
                          3.4133, 3.4714, 3.4727, 3.4133, 3.525 , 3.5997,
                          3.5997, 3.525 , 3.4122, 3.4738, 3.4728, 3.4109,
                          3.5259, 3.5997]
        for idx, _ in enumerate(self.lifepo4):
            cn_array.append(cnn.get_cn(self.lifepo4, idx, use_weights=True))

        self.assertArrayAlmostEqual(expected_array, cn_array, 2)
Beispiel #12
0
    def test_shifted_sites(self):
        cnn = CrystalNN()

        sites = [[0., 0.2, 0.2], [0, 0, 0]]
        struct = Structure([7, 0, 0, 0, 7, 0, 0, 0, 7], ['I'] * len(sites), sites)
        bonded_struct = cnn.get_bonded_structure(struct)

        sites_shifted = [[1., 0.2, 0.2], [0, 0, 0]]
        struct_shifted = Structure([7, 0, 0, 0, 7, 0, 0, 0, 7], ['I'] * len(sites_shifted),
                                   sites_shifted)
        bonded_struct_shifted = cnn.get_bonded_structure(struct_shifted)

        self.assertEqual(len(bonded_struct.get_connected_sites(0)),
                         len(bonded_struct_shifted.get_connected_sites(0)))
Beispiel #13
0
    def test_shifted_sites(self):
        cnn = CrystalNN()

        sites =  [[0., 0.2, 0.2], [0, 0, 0]]
        struct = Structure([7, 0, 0, 0, 7, 0, 0, 0, 7], ['I'] * len(sites), sites)
        bonded_struct = cnn.get_bonded_structure(struct)

        sites_shifted =  [[1., 0.2, 0.2], [0, 0, 0]]
        struct_shifted = Structure([7, 0, 0, 0, 7, 0, 0, 0, 7], ['I'] * len(sites_shifted),
                                   sites_shifted)
        bonded_struct_shifted = cnn.get_bonded_structure(struct_shifted)

        self.assertEqual(len(bonded_struct.get_connected_sites(0)),
                         len(bonded_struct_shifted.get_connected_sites(0)))
Beispiel #14
0
    def test_sanity(self):
        with self.assertRaises(ValueError):
            cnn = CrystalNN()
            cnn.get_cn(self.lifepo4, 0, use_weights=True)

        with self.assertRaises(ValueError):
            cnn = CrystalNN(weighted_cn=True)
            cnn.get_cn(self.lifepo4, 0, use_weights=False)
Beispiel #15
0
def get_local_env_method(method):  # pylint:disable=too-many-return-statements
    """get a local environment method based on its name"""
    method = method.lower()

    if method.lower() == "crystalnn":
        # see eq. 15 and 16 in
        # https://pubs.acs.org/doi/full/10.1021/acs.inorgchem.0c02996
        # for the x_diff_weight parameter.
        # in the paper it is called δen and it is set to 3
        # we found better results by lowering this weight
        return CrystalNN(porous_adjustment=True,
                         x_diff_weight=1.5,
                         search_cutoff=4.5)
    if method.lower() == "econnn":
        return EconNN()
    if method.lower() == "brunnernn":
        return BrunnerNN_relative()
    if method.lower() == "minimumdistance":
        return MinimumDistanceNN()
    if method.lower() == "vesta":
        return VESTA_NN
    if method.lower() == "voronoinn":
        return VoronoiNN()
    if method.lower() == "atr":
        return ATR_NN
    if method.lower() == "li":
        return LI_NN

    return JmolNN()
Beispiel #16
0
def main():
    args = _get_parser().parse_args()

    if args.yaml is not None:
        with open(args.yaml, 'r') as y:
            yaml = YAML(typ='safe', pure=True)
            yaml_args = yaml.load(y)

        nn = simple_nn(**yaml_args)
        if ('save_csv', False) in yaml_args.items():
            print(nn)

    else:
        if args.ox_states_dict:
            ox_states = args.ox_states_dict
        elif args.ox_states_list:
            ox_states = args.ox_states_list
        else:
            ox_states = None

        nn = simple_nn(args.start,
                       end=args.end,
                       ox_states=ox_states,
                       nn_method=CrystalNN(),
                       save_csv=args.save_csv,
                       csv_fname=args.csv_fname)

        if args.save_csv == False:
            print(nn)
    def test_zero_d_to_molecule_graph(self):
        comp_graphs = [
            self.mol_structure.graph.subgraph(c)
            for c in nx.weakly_connected_components(self.mol_structure.graph)
        ]

        mol_graph = zero_d_graph_to_molecule_graph(self.mol_structure,
                                                   comp_graphs[0])

        self.assertEqual(mol_graph.get_connected_sites(0)[0].index, 1)
        self.assertEqual(mol_graph.get_connected_sites(1)[1].index, 2)
        self.assertEqual(mol_graph.molecule.num_sites, 3)

        # test catching non zero dimensionality graphs
        comp_graphs = [
            self.graphite.graph.subgraph(c)
            for c in nx.weakly_connected_components(self.graphite.graph)
        ]
        self.assertRaises(ValueError, zero_d_graph_to_molecule_graph,
                          self.graphite, comp_graphs[0])

        # test for a troublesome structure
        s = loadfn(os.path.join(test_dir, "PH7CN3O3F.json.gz"))
        bs = CrystalNN().get_bonded_structure(s)
        comp_graphs = [
            bs.graph.subgraph(c)
            for c in nx.weakly_connected_components(bs.graph)
        ]
        mol_graph = zero_d_graph_to_molecule_graph(bs, comp_graphs[0])
        self.assertEqual(mol_graph.molecule.num_sites, 12)
Beispiel #18
0
def main():
    args = _get_parser().parse_args()

    if args.yaml is not None:
        with open(args.yaml, 'r') as y:
            yaml = YAML(typ='safe', pure=True)
            yaml_args = yaml.load(y)

        core = core_energy(**yaml_args)
        print(core)

    else:
        if args.ox_states_dict:
            ox_states = args.ox_states_dict
        elif args.ox_states_list:
            ox_states = args.ox_states_list
        else:
            ox_states = None

        core = core_energy(args.core_atom,
                           args.nn,
                           orbital=args.orbital,
                           ox_states=ox_states,
                           nn_method=CrystalNN(),
                           structure=args.structure)
        print(core)
    def __init__(
        self,
        use_conventional_cell: bool = True,
        near_neighbors: Optional[NearNeighbors] = None,
        mineral_matcher: Optional[MineralMatcher] = None,
        use_symmetry_equivalent_sites: bool = False,
        symprec: float = 0.01,
        simplify_molecules: bool = True,
        use_iupac_formula: bool = True,
        use_common_formulas: bool = True,
    ):
        if not near_neighbors:
            near_neighbors = CrystalNN()

        if mineral_matcher is None:
            mineral_matcher = MineralMatcher()

        self.use_conventional_cell = use_conventional_cell
        self.near_neighbors = near_neighbors
        self.mineral_matcher = mineral_matcher
        self.use_symmetry_equivalent_sites = use_symmetry_equivalent_sites
        self.symprec = symprec
        self.simplify_molecules = simplify_molecules
        self.use_common_formulas = use_common_formulas
        self.use_iupac_formula = use_iupac_formula
Beispiel #20
0
def main():
    args = _get_parser().parse_args()

    if args.yaml is not None:
        with open(args.yaml, 'r') as y:
            yaml = YAML(typ='safe', pure=True)
            yaml_args = yaml.load(y)

        ba = bond_analysis(**yaml_args)
        if ('save_csv', False) in yaml_args.items():
            print(ba)

    else:
        if args.ox_states_dict is not None:
            ox_states = args.ox_states_dict
        elif args.ox_states_list is not None:
            ox_states = args.ox_states_list
        else:
            ox_states = None

        ba = bond_analysis(args.structure,
                           args.bond,
                           nn_method=CrystalNN(),
                           ox_states=ox_states,
                           save_csv=args.save_csv,
                           csv_fname=args.csv_fname,
                           save_plt=args.save_plt,
                           plt_fname=args.plt_fname,
                           dpi=args.dpi,
                           color=args.color,
                           width=args.width,
                           height=args.height)

        if not args.save_csv:
            print(ba)
def get_Species_Substitution_Order(structure, dummies, species, to_ignore):

    els_removed = species.copy()
    for element in to_ignore:
        els_removed.remove(Element(element))

    subs = [list(p) for p in permutations(els_removed)]
    diff_coords = []
    struct_copies = []
    for sub in subs:
        copy = structure.copy()
        for dummy_ind in range(len(dummies)):
            copy[dummies[dummy_ind].symbol] = sub[dummy_ind]
        struct_copies.append(copy)
        coordination_numbers = []
        CN = CrystalNN(weighted_cn=True)
        for element_ind in range(len(copy.species)):
            cn = CN.get_cn(copy, element_ind, use_weights=True)
            coordination_numbers.append((copy.species[element_ind], cn))
        diff_coords.append(coordination_numbers)

    unique_cn_els = []
    for cn in diff_coords:
        cns = []
        for i in range(len(cn)):
            if cn[i] not in cns:
                cns.append(cn[i])
        unique_cn_els.append(cns)

    substitution_ind = None
    check_len = 300  # arbitrarily high number to start, used to get substitution scheme with lowest number of unique sites
    for unique_cn_el_ind in range(len(unique_cn_els)):
        if len(unique_cn_els[unique_cn_el_ind]) < check_len:
            substitution_ind = unique_cn_el_ind
            check_len = len(unique_cn_els[unique_cn_el_ind])
        else:
            continue

    ox_transform = AutoOxiStateDecorationTransformation()
    ox_species = ox_transform.apply_transformation(
        struct_copies[substitution_ind]).types_of_specie
    for specie in ox_species:
        for element in to_ignore:
            if specie.symbol == Element(element).symbol:
                ox_species.remove(specie)

    return subs[substitution_ind], ox_species
Beispiel #22
0
 def _set_cnn(self, method="JmolNN", porous_adjustment: bool = True):
     self.porous_adjustment = porous_adjustment
     if self._cnn is None or self._cnn_method != method.lower():
         if method.lower() == "crystalnn":
             self._cnn = CrystalNN(porous_adjustment=self.porous_adjustment)
         else:
             self._cnn = JmolNN()
         self._cnn_method = method.lower()
Beispiel #23
0
    def setUp(self):
        cnn = CrystalNN()

        self.mapi = cnn.get_bonded_structure(self.get_structure("mapi"))
        self.mapi_components = get_structure_components(
            self.mapi,
            inc_molecule_graph=True,
            inc_site_ids=True,
            inc_orientation=True)

        self.vdw_hetero = cnn.get_bonded_structure(self.get_structure("MoWS4"))
        self.vdw_hetero_components = get_structure_components(
            self.vdw_hetero,
            inc_molecule_graph=True,
            inc_site_ids=True,
            inc_orientation=True,
        )
Beispiel #24
0
    def test_get_formula_from_components(self):
        formula = get_formula_from_components(self.mapi_components,
                                              use_common_formulas=True,
                                              use_iupac_formula=True)
        self.assertTrue(formula, "CH3NH3PbI3")

        # check not using common formulas
        formula = get_formula_from_components(self.mapi_components,
                                              use_common_formulas=False,
                                              use_iupac_formula=True)
        self.assertTrue(formula, "CNH6PbI3")

        # check non-iupac ordering works
        formula = get_formula_from_components(self.mapi_components,
                                              use_iupac_formula=False,
                                              use_common_formulas=False)
        self.assertEqual(formula, "H6CNPbI3")

        # test multiple groups of different numbers of compositions
        s = CrystalNN().get_bonded_structure(self.get_structure("CuH8CN5Cl3"))
        comps = get_structure_components(s)
        formula = get_formula_from_components(comps,
                                              use_iupac_formula=True,
                                              use_common_formulas=True)
        self.assertEqual(formula, "(CuCN4HCl)2(NH2)2(H2)3(HCl)4")

        # test putting molecules first
        s = CrystalNN().get_bonded_structure(
            self.get_structure("ZrCuH8C2NCl6"))
        comps = get_structure_components(s)
        formula = get_formula_from_components(
            comps,
            molecules_first=False,
            use_iupac_formula=True,
            use_common_formulas=True,
        )
        self.assertEqual(formula, "ZrCuCl6(CH3)2NH2")

        formula = get_formula_from_components(
            comps,
            molecules_first=True,
            use_iupac_formula=True,
            use_common_formulas=True,
        )
        self.assertEqual(formula, "(CH3)2NH2ZrCuCl6")
    def setUp(self):
        cnn = CrystalNN()
        self.lifepo = cnn.get_bonded_structure(self.get_structure("LiFePO4"))
        self.graphite = cnn.get_bonded_structure(
            self.get_structure("Graphite"))
        self.cscl = cnn.get_bonded_structure(self.get_structure("CsCl"))

        tricky_structure = Structure(
            [5.79, 0.0, 0.0, 0, 5.79, 0.0, 0.0, 0.0, 5.79],
            ["B", "C", "C", "C", "C", "N", "N", "N", "N", "Ag"],
            [
                [0.0, 0.0, 0.0],
                [0.842, 0.842, 0.842],
                [0.158, 0.842, 0.158],
                [0.158, 0.158, 0.842],
                [0.842, 0.158, 0.158],
                [0.726, 0.726, 0.726],
                [0.274, 0.726, 0.274],
                [0.274, 0.274, 0.726],
                [0.726, 0.274, 0.274],
                [0.5, 0.5, 0.5],
            ],
        )
        self.tricky_structure = cnn.get_bonded_structure(tricky_structure)

        mol_structure = Structure(
            [[-2.316, 2.316, 2.160], [2.316, -2.316, 2.160],
             [2.316, 2.316, -2.160]],
            ["H", "C", "N"],
            [[0.752, 0.752, 0.000], [0.004, 0.004, 0.0], [0.272, 0.272, 0.0]],
        )
        self.mol_structure = cnn.get_bonded_structure(mol_structure)
        warnings.simplefilter("ignore")
Beispiel #26
0
def check_coords(structure, coord_num):
    '''
    Find if a cell keeps the topological crystal strucure after the DFT relax
    by check the coornadinate number of all the atoms

    Args:
        structure: pymatgen structure
        coord_num: coordinate number in the ideal structure
    Return:
        A boolean that is true when the structure is kept after geometry relaxation
    '''
    nn = CrystalNN()
    keep_coord_num = True
    for atom_site in range(len(structure)) :
        if len(nn.get_nn_info(structure, atom_site)) != coord_num :
            keep_coord_num = False
            break
    return keep_coord_num
Beispiel #27
0
    def dict_info_nn(self,only_li_struct=None,cutoff_r=5):

        """
        Creates a list of dictionaries recording all neighbor information for all Li in only_li_struct.

        Args:
            only_li_struct: the structure that only contains Li atoms.
            cutoff_r: set a radius such that within this radius the periodic image of itself would count as a near neighbor.

        Returns:
            A list of dictionaries that has all the neighbor information of all possible Li sites.
        """

        NN = CrystalNN(distance_cutoffs=(), x_diff_weight=0.0)
        neighbors_data = []

        if only_li_struct == None:
            only_li_struct = self.only_li_struct

        for i in range(0,len(only_li_struct)):
            info = {}
            info['position'] = [0,0,0,i]
            info['neighbors'] = []
            
            for j in NN.get_nn_info(only_li_struct,i):
                entry = list(j['image'])
                entry.append(j['site_index'])
                info['neighbors'].append(entry)

            if (only_li_struct.lattice.a)<=cutoff_r:
                peri_self = info['position'][:]
                peri_self[0] = 1
                info['neighbors'].append(peri_self)
            if (only_li_struct.lattice.b)<=cutoff_r:
                peri_self = info['position'][:]
                peri_self[1] = 1
                info['neighbors'].append(peri_self)
            if (only_li_struct.lattice.c)<=cutoff_r:
                peri_self = info['position'][:]
                peri_self[2] = 1
                info['neighbors'].append(peri_self)
            neighbors_data.append(info)

        return neighbors_data
Beispiel #28
0
    def test_noble_gas_material(self):
        cnn = CrystalNN()
        with self.assertRaises(RuntimeError):
            cnn.get_cn(self.he_bcc, 0, use_weights=False)

        cnn = CrystalNN(distance_cutoffs=(1.25, 5))
        self.assertAlmostEqual(cnn.get_cn(self.he_bcc, 0, use_weights=False),
                               8)
Beispiel #29
0
def bond_length_statis(structure): 
    '''
    Calculated some bond length statistics values in the structure
    the nearest atoms pairs are determined using pymatgen CrystalNN module
    EconNN BrunnerNN_real do not work well

    Args:
        structrue: pymatgen structure
    Return:
        the mean value, standard deviation and the range of all the cation-anion
        bond length in the crystal structure
    '''
    nn = CrystalNN()
    bond_len = []
    for j in range(len(structure)) : 
        for i in nn.get_nn_info(structure,j) :       
            bond_len.append(structure[j].distance(structure[i['site_index']]))
    bond_len = np.array(bond_len)
    return bond_len.mean(), bond_len.std(), bond_len.ptp()
Beispiel #30
0
def get_dimension(formula_dict):
    for key in formula_dict:
        for p in range(len(formula_dict[key])):
            print(key)
            bonded_structure = CrystalNN().get_bonded_structure(
                formula_dict[key][p]['structure'])
            formula_dict[key][p]['dimensionality'] = get_dimensionality_larsen(
                bonded_structure)
            #formula_dict[key][p]['dimensionality'] = get_dimensionality_larsen(
            #    formula_dict[key][p]['structure'])
            print(formula_dict[key][p]['dimensionality'])
Beispiel #31
0
def get_cooccurrence_pairs(struct):
    pairs = []
    struct_graph = StructureGraph.with_local_env_strategy(struct, CrystalNN())
    labels = {i: spec.name for i, spec in enumerate(struct.species)}
    G = struct_graph.graph.to_undirected()
    for n in labels:
        target = labels[n]
        # TODO what if the atom doesn't have any neighbors?
        neighbors = [labels[i] for i in G.neighbors(n)]
        for neighbor in neighbors:
            pairs.append((target, neighbor))
    return pairs
Beispiel #32
0
    def test_noble_gas_material(self):
        cnn = CrystalNN()

        self.assertEqual(cnn.get_cn(self.he_bcc, 0, use_weights=False), 0)

        cnn = CrystalNN(distance_cutoffs=(1.25, 5))
        self.assertEqual(cnn.get_cn(self.he_bcc, 0, use_weights=False), 8)
Beispiel #33
0
    def test_AverageBondLength(self):
        ft = AverageBondLength(VoronoiNN())
        self.assertAlmostEqual(ft.featurize(self.sc, 0)[0], 3.52)

        for i in range(len(self.cscl.sites)):
            self.assertAlmostEqual(ft.featurize(self.cscl, i)[0], 3.758562645051973)

        for i in range(len(self.b1.sites)):
            self.assertAlmostEqual(ft.featurize(self.b1, i)[0], 1.0)

        ft = AverageBondLength(CrystalNN())
        for i in range(len(self.cscl.sites)):
            self.assertAlmostEqual(ft.featurize(self.cscl, i)[0], 3.649153279231275)
Beispiel #34
0
    def test_sanity(self):
        with self.assertRaises(ValueError):
            cnn = CrystalNN()
            cnn.get_cn(self.lifepo4, 0, use_weights=True)

        with self.assertRaises(ValueError):
            cnn = CrystalNN(weighted_cn=True)
            cnn.get_cn(self.lifepo4, 0, use_weights=False)
Beispiel #35
0
 def count_cooccurrences_single(struct):
     counts = {}
     struct_graph = StructureGraph.with_local_env_strategy(struct, CrystalNN())
     labels = {i: spec.name for i, spec in enumerate(struct.species)}
     G = struct_graph.graph.to_undirected()
     for n in labels:
         target = labels[n]
         neighbors = [labels[i] for i in G.neighbors(n)]
         for neighbor in neighbors:
             key = frozenset([target, neighbor])
             if key not in counts:
                 counts[key] = 0
             counts[key] += 1
     return counts
Beispiel #36
0
    def test_AverageBondAngle(self):
        ft = AverageBondAngle(VoronoiNN())

        self.assertAlmostEqual(ft.featurize(self.sc, 0)[0], np.pi / 2)

        for i in range(len(self.cscl.sites)):
            self.assertAlmostEqual(ft.featurize(self.cscl, i)[0], 0.9289637531152273)

        for i in range(len(self.b1.sites)):
            self.assertAlmostEqual(ft.featurize(self.b1, i)[0], np.pi / 2)

        ft = AverageBondAngle(CrystalNN())
        for i in range(len(self.b1.sites)):
            self.assertAlmostEqual(ft.featurize(self.b1, i)[0], np.pi / 2)
    def setUp(self):
        cnn = CrystalNN()
        self.lifepo = cnn.get_bonded_structure(self.get_structure('LiFePO4'))
        self.graphite = cnn.get_bonded_structure(self.get_structure('Graphite'))
        self.cscl = cnn.get_bonded_structure(self.get_structure('CsCl'))

        tricky_structure = Structure(
            [5.79, 0., 0., 0, 5.79, 0., 0., 0., 5.79],
            ['B', 'C', 'C', 'C', 'C', 'N', 'N', 'N', 'N', 'Ag'],
            [[0.0, 0.0, 0.0], [0.842, 0.842, 0.842], [0.158, 0.842, 0.158],
             [0.158, 0.158, 0.842], [0.842, 0.158, 0.158],
             [0.726, 0.726, 0.726], [0.274, 0.726, 0.274],
             [0.274, 0.274, 0.726], [0.726, 0.274, 0.274], [0.5, 0.5, 0.5]])
        self.tricky_structure = cnn.get_bonded_structure(tricky_structure)

        mol_structure = Structure(
            [[-2.316, 2.316, 2.160], [2.316, -2.316, 2.160],
             [2.316, 2.316, -2.160]],
            ['H', 'C', 'N'],
            [[0.752, 0.752, 0.000], [0.004, 0.004, 0.], [0.272, 0.272, 0.]])
        self.mol_structure = cnn.get_bonded_structure(mol_structure)
Beispiel #38
0
 def test_cation_anion(self):
     cnn = CrystalNN(weighted_cn=True, cation_anion=True)
     self.assertAlmostEqual(cnn.get_cn(self.lifepo4, 0, use_weights=True),
                            5.8630, 2)
Beispiel #39
0
 def test_fixed_length(self):
     cnn = CrystalNN(fingerprint_length=30)
     nndata = cnn.get_nn_data(self.lifepo4, 0)
     self.assertEqual(len(nndata.cn_weights), 30)
     self.assertEqual(len(nndata.cn_nninfo), 30)
Beispiel #40
0
 def test_x_diff_weight(self):
     cnn = CrystalNN(weighted_cn=True, x_diff_weight=0)
     self.assertAlmostEqual(cnn.get_cn(self.lifepo4, 0, use_weights=True),
                            5.9522, 2)