def test_structure(self): quartz = self.quartz.structure np.testing.assert_array_almost_equal( quartz.lattice.matrix, [[4.913400, 0, 0], [-2.456700, 4.255129, 0], [0, 0, 5.405200]]) self.assertEqual(quartz.formula, "Si3 O6") self.assertNotIn("molecule-ID", self.quartz.atoms.columns) ethane = self.ethane.structure np.testing.assert_array_almost_equal(ethane.lattice.matrix, np.diag([10.0] * 3)) lbounds = np.array(self.ethane.box.bounds)[:, 0] coords = self.ethane.atoms[["x", "y", "z"]].values - lbounds np.testing.assert_array_almost_equal(ethane.cart_coords, coords) np.testing.assert_array_almost_equal(ethane.site_properties["charge"], self.ethane.atoms["q"]) tatb = self.tatb.structure frac_coords = tatb.frac_coords[381] real_frac_coords = frac_coords - np.floor(frac_coords) np.testing.assert_array_almost_equal( real_frac_coords, [0.01553397, 0.71487872, 0.14134139]) co = Structure.from_spacegroup(194, Lattice.hexagonal(2.50078, 4.03333), ["Co"], [[1 / 3, 2 / 3, 1 / 4]]) ld_co = LammpsData.from_structure(co) self.assertEqual(ld_co.structure.composition.reduced_formula, "Co") ni = Structure.from_spacegroup(225, Lattice.cubic(3.50804), ["Ni"], [[0, 0, 0]]) ld_ni = LammpsData.from_structure(ni) self.assertEqual(ld_ni.structure.composition.reduced_formula, "Ni")
def get_unit_cell(self, specie, lattice, alat): """ Get the unit cell from specie, lattice type and lattice constant. Args specie (str): Name of specie. lattice (str): The lattice type of structure. e.g. bcc or diamond. alat (float): The lattice constant of specific lattice and specie. """ if lattice == 'fcc': unit_cell = Structure.from_spacegroup(sg='Fm-3m', lattice=Lattice.cubic(alat), species=[specie], coords=[[0, 0, 0]]) elif lattice == 'bcc': unit_cell = Structure.from_spacegroup(sg='Im-3m', lattice=Lattice.cubic(alat), species=[specie], coords=[[0, 0, 0]]) elif lattice == 'diamond': unit_cell = Structure.from_spacegroup(sg='Fd-3m', lattice=Lattice.cubic(alat), species=[specie], coords=[[0, 0, 0]]) else: raise ValueError("Lattice type is invalid.") return unit_cell
def test_structure(self): quartz = self.quartz.structure np.testing.assert_array_equal(quartz.lattice.matrix, [[4.913400, 0, 0], [-2.456700, 4.255129, 0], [0, 0, 5.405200]]) self.assertEqual(quartz.formula, "Si3 O6") self.assertNotIn("molecule-ID", self.quartz.atoms.columns) ethane = self.ethane.structure np.testing.assert_array_equal(ethane.lattice.matrix, np.diag([10.0] * 3)) lbounds = np.array(self.ethane.box.bounds)[:, 0] coords = self.ethane.atoms[["x", "y", "z"]].values - lbounds np.testing.assert_array_equal(ethane.cart_coords, coords) np.testing.assert_array_equal(ethane.site_properties["charge"], self.ethane.atoms["q"]) tatb = self.tatb.structure frac_coords = tatb.frac_coords[381] real_frac_coords = frac_coords - np.floor(frac_coords) np.testing.assert_array_almost_equal(real_frac_coords, [0.01553397, 0.71487872, 0.14134139]) co = Structure.from_spacegroup(194, Lattice.hexagonal(2.50078, 4.03333), ["Co"], [[1/3, 2/3, 1/4]]) ld_co = LammpsData.from_structure(co) self.assertEqual(ld_co.structure.composition.reduced_formula, "Co") ni = Structure.from_spacegroup(225, Lattice.cubic(3.50804), ["Ni"], [[0, 0, 0]]) ld_ni = LammpsData.from_structure(ni) self.assertEqual(ld_ni.structure.composition.reduced_formula, "Ni")
def test_sulfide_type(self): # NaS2 -> polysulfide latt = Lattice.tetragonal(9.59650, 11.78850) species = ["Na"] * 2 + ["S"] * 2 coords = [[0.00000, 0.00000, 0.17000], [0.27600, 0.25000, 0.12500], [0.03400, 0.25000, 0.29600], [0.14700, 0.11600, 0.40000]] struct = Structure.from_spacegroup(122, latt, species, coords) self.assertEqual(sulfide_type(struct), "polysulfide") # NaCl type NaS -> sulfide latt = Lattice.cubic(5.75) species = ["Na", "S"] coords = [[0.00000, 0.00000, 0.00000], [0.50000, 0.50000, 0.50000]] struct = Structure.from_spacegroup(225, latt, species, coords) self.assertEqual(sulfide_type(struct), "sulfide") # Na2S2O3 -> None (sulfate) latt = Lattice.monoclinic(6.40100, 8.10000, 8.47400, 96.8800) species = ["Na"] * 2 + ["S"] * 2 + ["O"] * 3 coords = [[0.29706, 0.62396, 0.08575], [0.37673, 0.30411, 0.45416], [0.52324, 0.10651, 0.21126], [0.29660, -0.04671, 0.26607], [0.17577, 0.03720, 0.38049], [0.38604, -0.20144, 0.33624], [0.16248, -0.08546, 0.11608]] struct = Structure.from_spacegroup(14, latt, species, coords) self.assertEqual(sulfide_type(struct), None) # Na3PS3O -> sulfide latt = Lattice.orthorhombic(9.51050, 11.54630, 5.93230) species = ["Na"] * 2 + ["S"] * 2 + ["P", "O"] coords = [[0.19920, 0.11580, 0.24950], [0.00000, 0.36840, 0.29380], [0.32210, 0.36730, 0.22530], [0.50000, 0.11910, 0.27210], [0.50000, 0.29400, 0.35500], [0.50000, 0.30300, 0.61140]] struct = Structure.from_spacegroup(36, latt, species, coords) self.assertEqual(sulfide_type(struct), "sulfide")
def setUp(self): self.structure1 = Structure.from_spacegroup("Fd-3m", Lattice.cubic(5.46873), ["Si"], [[0, 0, 0]]) self.structure2 = Structure.from_spacegroup("Fm-3m", Lattice.cubic(5.69169), ['Na', 'Cl'], [[0, 0, 0], [0, 0, 0.5]]) self.structure3 = Structure.from_spacegroup("Pm-3m", Lattice.cubic(3.88947), ['Ca', 'Ti', 'O'], [[0.5, 0.5, 0.5], [0, 0, 0], [0, 0, 0.5]])
def setUp(self): self.unary_struct = Structure.from_spacegroup("Im-3m", Lattice.cubic(3.4268), ["Li"], [[0, 0, 0]]) self.binary_struct = Structure.from_spacegroup( "Fm-3m", Lattice.cubic(5.69169), ['Na', 'Cl'], [[0, 0, 0], [0, 0, 0.5]]) self.describer = SmoothOverlapAtomicPosition(cutoff=4.8, l_max=8, n_max=8)
def setUp(self): self.unary_struct = Structure.from_spacegroup('Im-3m', Lattice.cubic(3.4268), [{ "Li": 1 }], [[0, 0, 0]]) self.binary_struct = Structure.from_spacegroup( 225, Lattice.cubic(5.69169), ['Na', 'Cl'], [[0, 0, 0], [0, 0, 0.5]]) self.describer = SOAPDescriptor(cutoff=4.8, l_max=8, n_max=8)
def setUp(self): self.structure1 = Structure.from_spacegroup("Fd-3m", Lattice.cubic(5.46873), ["Si"], [[0, 0, 0]]) self.structure2 = Structure.from_spacegroup("Fm-3m", Lattice.cubic(5.69169), ["Na", "Cl"], [[0, 0, 0], [0, 0, 0.5]]) self.structure3 = Structure.from_spacegroup( "Pm-3m", Lattice.cubic(3.88947), ["Ca", "Ti", "O"], [[0.5, 0.5, 0.5], [0, 0, 0], [0, 0, 0.5]])
def setUp(self): element_profile = {'Ni': {'r': 0.5, 'w': 1}} describer1 = BispectrumCoefficients(rcutfac=4.1, twojmax=8, element_profile=element_profile, quadratic=False, pot_fit=True) model1 = LinearModel(describer=describer1) model1.model.coef_ = coeff model1.model.intercept_ = intercept snap1 = SNAPotential(model=model1) snap1.specie = Element('Ni') self.ff_settings1 = snap1 describer2 = BispectrumCoefficients(rcutfac=4.1, twojmax=8, element_profile=element_profile, quadratic=True, pot_fit=True) model2 = LinearModel(describer=describer2) model2.model.coef_ = coeff model2.model.intercept_ = intercept snap2 = SNAPotential(model=model2) snap2.specie = Element('Ni') self.ff_settings2 = snap2 self.struct = Structure.from_spacegroup('Fm-3m', Lattice.cubic(3.506), ['Ni'], [[0, 0, 0]])
def setUp(self): latt = Lattice.cubic(4.17) species = ["Ni", "O"] coords = [[0, 0, 0], [0.5, 0.5, 0.5]] self.NiO = Structure.from_spacegroup(225, latt, species, coords) latt = Lattice([[2.085, 2.085, 0.0], [0.0, -2.085, -2.085], [-2.085, 2.085, -4.17]]) species = ["Ni", "Ni", "O", "O"] coords = [[0.5, 0, 0.5], [0, 0, 0], [0.25, 0.5, 0.25], [0.75, 0.5, 0.75]] self.NiO_AFM_111 = Structure(latt, species, coords) self.NiO_AFM_111.add_spin_by_site([-5, 5, 0, 0]) latt = Lattice([[2.085, 2.085, 0], [0, 0, -4.17], [-2.085, 2.085, 0]]) species = ["Ni", "Ni", "O", "O"] coords = [[0.5, 0.5, 0.5], [0, 0, 0], [0, 0.5, 0], [0.5, 0, 0.5]] self.NiO_AFM_001 = Structure(latt, species, coords) self.NiO_AFM_001.add_spin_by_site([-5, 5, 0, 0]) parser = CifParser(os.path.join(test_dir, 'Fe3O4.cif')) self.Fe3O4 = parser.get_structures()[0] trans = AutoOxiStateDecorationTransformation() self.Fe3O4_oxi = trans.apply_transformation(self.Fe3O4) parser = CifParser(os.path.join(test_dir, 'Li8Fe2NiCoO8.cif')) self.Li8Fe2NiCoO8 = parser.get_structures()[0] self.Li8Fe2NiCoO8.remove_oxidation_states() warnings.simplefilter("ignore")
def setUp(self): element_profile = {"Ni": {"r": 0.5, "w": 1}} describer1 = BispectrumCoefficients(rcutfac=4.1, twojmax=8, element_profile=element_profile, quadratic=False, pot_fit=True) model1 = SKLModel(describer=describer1, model=LinearRegression()) model1.model.coef_ = coeff model1.model.intercept_ = intercept snap1 = SNAPotential(model=model1) self.ff_settings1 = snap1 describer2 = BispectrumCoefficients(rcutfac=4.1, twojmax=8, element_profile=element_profile, quadratic=True, pot_fit=True) model2 = SKLModel(describer=describer2, model=LinearRegression()) model2.model.coef_ = coeff model2.model.intercept_ = intercept snap2 = SNAPotential(model=model2) self.ff_settings2 = snap2 self.struct = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.506), ["Ni"], [[0, 0, 0]])
def setUp(self): self.structure = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.5), ["Ni"], [[0, 0, 0]]) lattice = Lattice.cubic(3.010) frac_coords = [[0.00000, 0.00000, 0.00000], [0.00000, 0.50000, 0.50000], [0.50000, 0.00000, 0.50000], [0.50000, 0.50000, 0.00000], [0.50000, 0.00000, 0.00000], [0.50000, 0.50000, 0.50000], [0.00000, 0.00000, 0.50000], [0.00000, 0.50000, 0.00000]] species = ['Mg', 'Mg', 'Mg', 'Mg', 'O', 'O', 'O', 'O'] self.MgO = Structure(lattice, species, frac_coords) slabs = generate_all_slabs(self.structure, max_index=2, min_slab_size=6.0, min_vacuum_size=15.0, max_normal_search=1, center_slab=True) self.slab_dict = {''.join([str(i) for i in slab.miller_index]): slab for slab in slabs} self.asf_211 = AdsorbateSiteFinder(self.slab_dict["211"]) self.asf_100 = AdsorbateSiteFinder(self.slab_dict["100"]) self.asf_111 = AdsorbateSiteFinder(self.slab_dict["111"]) self.asf_110 = AdsorbateSiteFinder(self.slab_dict["110"]) self.asf_struct = AdsorbateSiteFinder( Structure.from_sites(self.slab_dict["111"].sites))
def setUp(self): with open(os.path.join(test_dir, 'test_toec_data.json')) as f: self.data_dict = json.load(f) self.strains = [Strain(sm) for sm in self.data_dict['strains']] self.pk_stresses = [Stress(d) for d in self.data_dict['pk_stresses']] self.c2 = self.data_dict["C2_raw"] self.c3 = self.data_dict["C3_raw"] self.exp = ElasticTensorExpansion.from_voigt([self.c2, self.c3]) self.cu = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.623), ["Cu"], [[0] * 3]) indices = [(0, 0), (0, 1), (3, 3)] values = [167.8, 113.5, 74.5] cu_c2 = ElasticTensor.from_values_indices(values, indices, structure=self.cu, populate=True) indices = [(0, 0, 0), (0, 0, 1), (0, 1, 2), (0, 3, 3), (0, 5, 5), (3, 4, 5)] values = [-1507., -965., -71., -7., -901., 45.] cu_c3 = Tensor.from_values_indices(values, indices, structure=self.cu, populate=True) self.exp_cu = ElasticTensorExpansion([cu_c2, cu_c3]) cu_c4 = Tensor.from_voigt(self.data_dict["Cu_fourth_order"]) self.exp_cu_4 = ElasticTensorExpansion([cu_c2, cu_c3, cu_c4]) warnings.simplefilter("ignore")
def setUp(self): self.structure = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.5), ["Ni"], [[0, 0, 0]]) lattice = Lattice.cubic(3.010) frac_coords = [ [0.00000, 0.00000, 0.00000], [0.00000, 0.50000, 0.50000], [0.50000, 0.00000, 0.50000], [0.50000, 0.50000, 0.00000], [0.50000, 0.00000, 0.00000], [0.50000, 0.50000, 0.50000], [0.00000, 0.00000, 0.50000], [0.00000, 0.50000, 0.00000], ] species = ["Mg", "Mg", "Mg", "Mg", "O", "O", "O", "O"] self.MgO = Structure(lattice, species, frac_coords) slabs = generate_all_slabs( self.structure, max_index=2, min_slab_size=6.0, min_vacuum_size=15.0, max_normal_search=1, center_slab=True, ) self.slab_dict = { "".join([str(i) for i in slab.miller_index]): slab for slab in slabs } self.asf_211 = AdsorbateSiteFinder(self.slab_dict["211"]) self.asf_100 = AdsorbateSiteFinder(self.slab_dict["100"]) self.asf_111 = AdsorbateSiteFinder(self.slab_dict["111"]) self.asf_110 = AdsorbateSiteFinder(self.slab_dict["110"]) self.asf_struct = AdsorbateSiteFinder( Structure.from_sites(self.slab_dict["111"].sites))
def disorder(self,apecies,spacegroup="C2"): from pymatgen import Structure, Lattice from pymatgen.io.vasp.sets import MPRelaxSet import numpy as np import os cod=[] for i in apecies: cod.append(np.random.rand(3).tolist()) # print(cod) custom_settings = {"NELMIN": 5} specie = apecies cuau = Structure.from_spacegroup(sg=spacegroup, lattice=Lattice.cubic(10), species=apecies, coords=cod) relax = MPRelaxSet(cuau, user_incar_settings=custom_settings) os.chdir(self.dire) print (os.getcwd()) gge=[] for n in specie: for key,value in n.items(): gge.append(key) jji=[] for j in gge: jji.append(str(j)[:-2]) str1 = "-".join(jji) print (str1) relax.write_input(str(str1))
def test_from_structure(self): latt = Lattice.monoclinic(9.78746, 4.75058, 8.95892, 115.9693) structure = Structure.from_spacegroup( 15, latt, ["Os", "O", "O"], [ [0, 0.25583, 0.75], [0.11146, 0.46611, 0.91631], [0.11445, 0.04564, 0.69518], ], ) velocities = np.random.randn(20, 3) * 0.1 structure.add_site_property("velocities", velocities) ld = LammpsData.from_structure(structure=structure, ff_elements=["O", "Os", "Na"]) i = random.randint(0, 19) a = latt.matrix[0] va = velocities[i].dot(a) / np.linalg.norm(a) self.assertAlmostEqual(va, ld.velocities.loc[i + 1, "vx"]) self.assertAlmostEqual(velocities[i, 1], ld.velocities.loc[i + 1, "vy"]) np.testing.assert_array_almost_equal(ld.masses["mass"], [22.989769, 190.23, 15.9994]) np.testing.assert_array_equal(ld.atoms["type"], [2] * 4 + [3] * 16)
def test_sulfide_type(self): # NaS2 -> polysulfide latt = Lattice.tetragonal(9.59650, 11.78850) species = ["Na"] * 2 + ["S"] * 2 coords = [[0.00000, 0.00000, 0.17000], [0.27600, 0.25000, 0.12500], [0.03400, 0.25000, 0.29600], [0.14700, 0.11600, 0.40000]] struct = Structure.from_spacegroup(122, latt, species, coords) self.assertEqual(sulfide_type(struct), "polysulfide") # NaCl type NaS -> sulfide latt = Lattice.cubic(5.75) species = ["Na", "S"] coords = [[0.00000, 0.00000, 0.00000], [0.50000, 0.50000, 0.50000]] struct = Structure.from_spacegroup(225, latt, species, coords) self.assertEqual(sulfide_type(struct), "sulfide") # Na2S2O3 -> None (sulfate) latt = Lattice.monoclinic(6.40100, 8.10000, 8.47400, 96.8800) species = ["Na"] * 2 + ["S"] * 2 + ["O"] * 3 coords = [[0.29706, 0.62396, 0.08575], [0.37673, 0.30411, 0.45416], [0.52324, 0.10651, 0.21126], [0.29660, -0.04671, 0.26607], [0.17577, 0.03720, 0.38049], [0.38604, -0.20144, 0.33624], [0.16248, -0.08546, 0.11608]] struct = Structure.from_spacegroup(14, latt, species, coords) self.assertEqual(sulfide_type(struct), None) # Na3PS3O -> sulfide latt = Lattice.orthorhombic(9.51050, 11.54630, 5.93230) species = ["Na"] * 2 + ["S"] * 2 + ["P", "O"] coords = [[0.19920, 0.11580, 0.24950], [0.00000, 0.36840, 0.29380], [0.32210, 0.36730, 0.22530], [0.50000, 0.11910, 0.27210], [0.50000, 0.29400, 0.35500], [0.50000, 0.30300, 0.61140]] struct = Structure.from_spacegroup(36, latt, species, coords) self.assertEqual(sulfide_type(struct), "sulfide") # test for unphysical cells struct.scale_lattice(struct.volume*10) self.assertEqual(sulfide_type(struct), "sulfide")
def bi(self): """Return BCC Bi structure.""" bcc_bi = Structure.from_spacegroup( "Im-3m", Lattice.cubic(3.453), ["Bi"], [[0, 0, 0]] ) bcc_bi = bcc_bi.get_reduced_structure("niggli") return bcc_bi
def setUp(self): self.unary_struct = Structure.from_spacegroup("Im-3m", Lattice.cubic(3.4268), ["Li"], [[0, 0, 0]]) self.binary_struct = Structure.from_spacegroup( "Fm-3m", Lattice.cubic(5.69169), ['Na', 'Cl'], [[0, 0, 0], [0, 0, 0.5]]) self.r_etas = [0.01, 0.02, 0.05] self.r_shift = [0] self.zetas = [1.0, 4.0] self.a_etas = [0.01, 0.05] self.lambdas = [-1, 1] self.describer = BPSymmetryFunctions(cutoff=4.8, r_etas=self.r_etas, r_shift=self.r_shift, lambdas=self.lambdas, a_etas=self.a_etas, zetas=self.zetas)
def setUp(self): super(TestAdsorptionWorkflow, self).setUp() self.struct_ir = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.875728), ["Ir"], [[0, 0, 0]]) sgp = {"max_index": 1, "min_slab_size": 7.0, "min_vacuum_size": 20.0} slabs = generate_all_slabs(self.struct_ir, **sgp) slabs = [slab for slab in slabs if slab.miller_index==(1, 0, 0)] sgp.pop("max_index") self.wf_1 = get_wf_surface(slabs, [Molecule("H", [[0, 0, 0]])], self.struct_ir, sgp, db_file=os.path.join(db_dir, "db.json"))
def setUpClass(cls): cls.s = Structure.from_spacegroup('Fm-3m', Lattice.cubic(5.69169), ['Na', 'Cl'], [[0, 0, 0], [0, 0, 0.5]]) cls.dummy_model = MEGNetModel(100, 2, nblocks=1, n1=4, n2=2, n3=2, npass=1)
def setUp(self): self.structure = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.5), ["Ni"], [[0, 0, 0]]) slabs = generate_all_slabs(self.structure, max_index=2, min_slab_size=6.0, min_vacuum_size=15.0, max_normal_search=1, center_slab=True) self.slab_dict = {''.join([str(i) for i in slab.miller_index]): slab for slab in slabs} self.asf_211 = AdsorbateSiteFinder(self.slab_dict["211"]) self.asf_100 = AdsorbateSiteFinder(self.slab_dict["100"]) self.asf_111 = AdsorbateSiteFinder(self.slab_dict["111"]) self.asf_110 = AdsorbateSiteFinder(self.slab_dict["110"])
def setUp(self): element_profile = {'Ni': {'r': 0.5, 'w': 1}} describer = BispectrumCoefficients(cutoff=4.1, twojmax=8, element_profile=element_profile, pot_fit=True) model = SKLModel(describer=describer, model=LinearRegression()) model.model.coef_ = coeff model.model.intercept_ = intercept snap = SNAPotential(model=model) self.struct = Structure.from_spacegroup('Fm-3m', Lattice.cubic(3.506), ['Ni'], [[0, 0, 0]]) self.ff_settings = snap
def setUp(self): super(TestAdsorptionWorkflow, self).setUp() self.struct_ir = Structure.from_spacegroup( "Fm-3m", Lattice.cubic(3.875728), ["Ir"], [[0, 0, 0]]) sgp = {"max_index": 1, "min_slab_size": 7.0, "min_vacuum_size": 20.0} self.slabs = generate_all_slabs(self.struct_ir, **sgp) self.slab_100 = [slab for slab in self.slabs if slab.miller_index==(1, 0, 0)][0] self.wf_1 = get_wf_slab(self.slab_100, True, [Molecule("H", [[0, 0, 0]])], db_file=os.path.join(db_dir, "db.json"))
def setUp(self): self.unary_struct = Structure.from_spacegroup('Im-3m', Lattice.cubic(3.4268), [{ "Li": 1 }], [[0, 0, 0]]) self.num_symm2 = 3 self.a_etas = [0.01, 0.05] self.describer = BPSymmetryFunctions(dmin=2.0, cutoff=4.8, num_symm2=self.num_symm2, a_etas=self.a_etas)
def test_md(self): s = Structure.from_spacegroup(225, Lattice.cubic(3.62126), ["Cu"], [[0, 0, 0]]) ld = LammpsData.from_structure(s, atom_style="atomic") ff = "\n".join(["pair_style eam", "pair_coeff * * Cu_u3.eam"]) md = LammpsRun.md(data=ld, force_field=ff, temperature=1600.0, nsteps=10000) md.write_inputs(output_dir="md") with open(os.path.join("md", "in.md")) as f: md_script = f.read() script_string = """# Sample input script template for MD # Initialization units metal atom_style atomic # Atom definition read_data md.data #read_restart md.restart # Force field settings (consult official document for detailed formats) pair_style eam pair_coeff * * Cu_u3.eam # Create velocities velocity all create 1600.0 142857 mom yes rot yes dist gaussian # Ensemble constraints #fix 1 all nve fix 1 all nvt temp 1600.0 1600.0 0.1 #fix 1 all npt temp 1600.0 1600.0 0.1 iso $pressure $pressure 1.0 # Various operations within timestepping #fix ... #compute ... # Output settings #thermo_style custom ... # control the thermo data type to output thermo 100 # output thermo data every N steps #dump 1 all atom 100 traj.*.gz # dump a snapshot every 100 steps # Actions run 10000 """ self.assertEqual(md_script, script_string) self.assertTrue(os.path.exists(os.path.join("md", "md.data")))
def setUp(self): # trivial example, simple square lattice for testing structure = Structure(Lattice.tetragonal(5.0, 50.0), ['H'], [[0, 0, 0]]) self.square_sg = StructureGraph.with_empty_graph(structure, edge_weight_name="", edge_weight_units="") self.square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(1, 0, 0)) self.square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(-1, 0, 0)) self.square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, 1, 0)) self.square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, -1, 0)) # body-centered square lattice for testing structure = Structure(Lattice.tetragonal(5.0, 50.0), ['H', 'He'], [[0, 0, 0], [0.5, 0.5, 0.5]]) self.bc_square_sg = StructureGraph.with_empty_graph(structure, edge_weight_name="", edge_weight_units="") self.bc_square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(1, 0, 0)) self.bc_square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(-1, 0, 0)) self.bc_square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, 1, 0)) self.bc_square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, -1, 0)) self.bc_square_sg.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(0, 0, 0)) self.bc_square_sg.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(-1, 0, 0)) self.bc_square_sg.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(-1, -1, 0)) self.bc_square_sg.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(0, -1, 0)) # body-centered square lattice for testing # directions reversed, should be equivalent to as bc_square structure = Structure(Lattice.tetragonal(5.0, 50.0), ['H', 'He'], [[0, 0, 0], [0.5, 0.5, 0.5]]) self.bc_square_sg_r = StructureGraph.with_empty_graph(structure, edge_weight_name="", edge_weight_units="") self.bc_square_sg_r.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(1, 0, 0)) self.bc_square_sg_r.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(-1, 0, 0)) self.bc_square_sg_r.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, 1, 0)) self.bc_square_sg_r.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, -1, 0)) self.bc_square_sg_r.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(0, 0, 0)) self.bc_square_sg_r.add_edge(1, 0, from_jimage=(-1, 0, 0), to_jimage=(0, 0, 0)) self.bc_square_sg_r.add_edge(1, 0, from_jimage=(-1, -1, 0), to_jimage=(0, 0, 0)) self.bc_square_sg_r.add_edge(1, 0, from_jimage=(0, -1, 0), to_jimage=(0, 0, 0)) # MoS2 example, structure graph obtained from critic2 # (not ground state, from mp-1023924, single layer) stdout_file = os.path.join(os.path.dirname(__file__), "..", "..", "..", 'test_files/critic2/MoS2_critic2_stdout.txt') with open(stdout_file, 'r') as f: reference_stdout = f.read() self.structure = Structure.from_file(os.path.join(os.path.dirname(__file__), "..", "..", "..", 'test_files/critic2/MoS2.cif')) c2o = Critic2Output(self.structure, reference_stdout) self.mos2_sg = c2o.structure_graph(edge_weight="bond_length", edge_weight_units="Å") latt = Lattice.cubic(4.17) species = ["Ni", "O"] coords = [[0, 0, 0], [0.5, 0.5, 0.5]] self.NiO = Structure.from_spacegroup(225, latt, species, coords).get_primitive_structure()
def test_apply_transformation(self): Li_bulk = Structure.from_spacegroup("Im-3m", Lattice.cubic(2.96771), ["Li"], [[0, 0, 0]]) gb_gen_params_s3 = {"rotation_axis": [1, 1, 1], "rotation_angle": 60.0, "expand_times": 2, "vacuum_thickness": 0.0, "normal": True, "ratio": None, "plane": None} gbg = GBGenerator(Li_bulk) gb_from_generator = gbg.gb_from_parameters(**gb_gen_params_s3) gbt_s3 = GrainBoundaryTransformation(**gb_gen_params_s3) gb_from_trans = gbt_s3.apply_transformation(Li_bulk) self.assertArrayAlmostEqual(gb_from_generator.lattice.matrix, gb_from_trans.lattice.matrix) self.assertArrayAlmostEqual(gb_from_generator.cart_coords, gb_from_trans.cart_coords)
def setUp(self): self.s1 = Structure.from_spacegroup(225, Lattice.cubic(5.69169), ["Na", "Cl"], [[0, 0, 0], [0, 0, 0.5]]) self.s2 = Structure.from_dict({'@class': 'Structure', '@module': 'pymatgen.core.structure', 'charge': None, 'lattice': {'a': 5.488739045730133, 'alpha': 60.0000000484055, 'b': 5.488739048031658, 'beta': 60.00000003453459, 'c': 5.48873905, 'gamma': 60.000000071689925, 'matrix': [[4.75338745, 0.0, 2.74436952], [1.58446248, 4.48153667, 2.74436952], [0.0, 0.0, 5.48873905]], 'volume': 116.92375473740876}, 'sites': [{'abc': [0.5, 0.5, 0.5], 'label': 'Al', 'properties': {'coordination_no': 10, 'forces': [0.0, 0.0, 0.0]}, 'species': [{'element': 'Al', 'occu': 1}], 'xyz': [3.168924965, 2.240768335, 5.488739045]}, {'abc': [0.5, 0.5, 0.0], 'label': 'Al', 'properties': {'coordination_no': 10, 'forces': [0.0, 0.0, 0.0]}, 'species': [{'element': 'Al', 'occu': 1}], 'xyz': [3.168924965, 2.240768335, 2.74436952]}, {'abc': [0.0, 0.5, 0.5], 'label': 'Al', 'properties': {'coordination_no': 10, 'forces': [0.0, 0.0, 0.0]}, 'species': [{'element': 'Al', 'occu': 1}], 'xyz': [0.79223124, 2.240768335, 4.116554285]}, {'abc': [0.5, 0.0, 0.5], 'label': 'Al', 'properties': {'coordination_no': 10, 'forces': [0.0, 0.0, 0.0]}, 'species': [{'element': 'Al', 'occu': 1}], 'xyz': [2.376693725, 0.0, 4.116554285]}, {'abc': [0.875, 0.875, 0.875], 'label': 'Lu', 'properties': {'coordination_no': 16, 'forces': [0.0, 0.0, 0.0]}, 'species': [{'element': 'Lu', 'occu': 1}], 'xyz': [5.54561868875, 3.9213445862499996, 9.60529332875]}, {'abc': [0.125, 0.125, 0.125], 'label': 'Lu', 'properties': {'coordination_no': 16, 'forces': [0.0, 0.0, 0.0]}, 'species': [{'element': 'Lu', 'occu': 1}], 'xyz': [0.79223124125, 0.56019208375, 1.37218476125]}]})
def test_apply_transformation(self): with warnings.catch_warnings(): warnings.simplefilter("ignore") Al_bulk = Structure.from_spacegroup("Fm-3m", Lattice.cubic(2.8575585), ["Al"], [[0, 0, 0]]) gb_gen_params_s5 = {"rotation_axis": [1, 0, 0], "rotation_angle": 53.13010235415599, "expand_times": 3, "vacuum_thickness": 0.0, "normal": True, "plane": [0, -1, -3], 'rm_ratio': 0.6} gbg = GrainBoundaryGenerator(Al_bulk) gb_from_generator = gbg.gb_from_parameters(**gb_gen_params_s5) gbt_s5 = GrainBoundaryTransformation(**gb_gen_params_s5) gb_from_trans = gbt_s5.apply_transformation(Al_bulk) self.assertArrayAlmostEqual(gb_from_generator.lattice.matrix, gb_from_trans.lattice.matrix) self.assertArrayAlmostEqual(gb_from_generator.cart_coords, gb_from_trans.cart_coords)
def setUp(self): self.structure = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.5), ["Ni"], [[0, 0, 0]]) slabs = generate_all_slabs(self.structure, max_index=2, min_slab_size=6.0, min_vacuum_size=15.0, max_normal_search=1, center_slab=True) self.slab_dict = { ''.join([str(i) for i in slab.miller_index]): slab for slab in slabs } self.asf_211 = AdsorbateSiteFinder(self.slab_dict["211"]) self.asf_100 = AdsorbateSiteFinder(self.slab_dict["100"]) self.asf_111 = AdsorbateSiteFinder(self.slab_dict["111"]) self.asf_110 = AdsorbateSiteFinder(self.slab_dict["110"])
def from_parameters(structure_parameters: StructureParameters) -> Structure: """Generates a pymatgen ``Structure`` object using a material's structural parameters. :param structure_parameters: A ``StructureParameters`` tuple that specifies a material's crystal structure. :return: A pymatgen ``Structure`` object. """ cell_lattice: Lattice = Lattice.from_lengths_and_angles( abc=structure_parameters.abc, ang=structure_parameters.ang) cell_structure: Structure = Structure.from_spacegroup( sg=structure_parameters.spacegroup, lattice=cell_lattice, species=structure_parameters.species, coords=structure_parameters.coordinates, ) return cell_structure
def test_from_structure(self): latt = Lattice.monoclinic(9.78746, 4.75058, 8.95892, 115.9693) structure = Structure.from_spacegroup(15, latt, ["Os", "O", "O"], [[0, 0.25583, 0.75], [0.11146, 0.46611, 0.91631], [0.11445, 0.04564, 0.69518]]) velocities = np.random.randn(20, 3) * 0.1 structure.add_site_property("velocities", velocities) ld = LammpsData.from_structure(structure=structure, ff_elements=["O", "Os", "Na"]) i = random.randint(0, 19) a = latt.matrix[0] va = velocities[i].dot(a) / np.linalg.norm(a) self.assertAlmostEqual(va, ld.velocities.loc[i + 1, "vx"]) self.assertAlmostEqual(velocities[i, 1], ld.velocities.loc[i + 1, "vy"]) np.testing.assert_array_almost_equal(ld.masses["mass"], [22.989769, 190.23, 15.9994]) np.testing.assert_array_equal(ld.atoms["type"], [2] * 4 + [3] * 16)
def test_describe(self): s = Structure.from_spacegroup(225, Lattice.cubic(5.69169), ['Na', 'Cl'], [[0, 0, 0], [0, 0, 0.5]]) profile = dict(Na=dict(r=0.3, w=0.9), Cl=dict(r=0.7, w=3.0)) s *= [2, 2, 2] structures = [s] * 10 for s in structures: n = np.random.randint(4) inds = np.random.randint(16, size=n) s.remove_sites(inds) bc_atom = BispectrumCoefficients(5, 3, profile, diagonalstyle=2, quadratic=False, pot_fit=False) df_atom = bc_atom.describe_all(structures) for i, s in enumerate(structures): df_s = df_atom.xs(i, level='input_index') self.assertEqual(df_s.shape, (len(s), 4)) self.assertTrue(df_s.equals(bc_atom.describe(s))) bc_pot = BispectrumCoefficients(5, 3, profile, diagonalstyle=2, quadratic=False, pot_fit=True) df_pot = bc_pot.describe_all(structures, include_stress=True) for i, s in enumerate(structures): df_s = df_pot.xs(i, level='input_index') self.assertEqual(df_s.shape, ((1 + len(s) * 3 + 6, 10))) self.assertTrue( df_s.equals(bc_pot.describe(s, include_stress=True))) sna = df_s.iloc[0] for specie in ['Na', 'Cl']: self.assertAlmostEqual( sna[specie, 'n'], s.composition.fractional_composition[specie]) np.testing.assert_array_equal(df_s[specie, 'n'][1:], np.zeros(len(s) * 3 + 6))
def test_apply_transformation(self): s = self.get_structure("LiFePO4") trans = SlabTransformation([0, 0, 1], 10, 10, shift=0.25) gen = SlabGenerator(s, [0, 0, 1], 10, 10) slab_from_gen = gen.get_slab(0.25) slab_from_trans = trans.apply_transformation(s) self.assertArrayAlmostEqual(slab_from_gen.lattice.matrix, slab_from_trans.lattice.matrix) self.assertArrayAlmostEqual(slab_from_gen.cart_coords, slab_from_trans.cart_coords) fcc = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3), ["Fe"], [[0, 0, 0]]) trans = SlabTransformation([1, 1, 1], 10, 10) slab_from_trans = trans.apply_transformation(fcc) gen = SlabGenerator(fcc, [1, 1, 1], 10, 10) slab_from_gen = gen.get_slab() self.assertArrayAlmostEqual(slab_from_gen.lattice.matrix, slab_from_trans.lattice.matrix) self.assertArrayAlmostEqual(slab_from_gen.cart_coords, slab_from_trans.cart_coords)
def test_apply_transformation(self): s = self.get_structure("LiFePO4") trans = SlabTransformation([0, 0, 1], 10, 10, shift = 0.25) gen = SlabGenerator(s, [0, 0, 1], 10, 10) slab_from_gen = gen.get_slab(0.25) slab_from_trans = trans.apply_transformation(s) self.assertArrayAlmostEqual(slab_from_gen.lattice.matrix, slab_from_trans.lattice.matrix) self.assertArrayAlmostEqual(slab_from_gen.cart_coords, slab_from_trans.cart_coords) fcc = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3), ["Fe"], [[0, 0, 0]]) trans = SlabTransformation([1, 1, 1], 10, 10) slab_from_trans = trans.apply_transformation(fcc) gen = SlabGenerator(fcc, [1, 1, 1], 10, 10) slab_from_gen = gen.get_slab() self.assertArrayAlmostEqual(slab_from_gen.lattice.matrix, slab_from_trans.lattice.matrix) self.assertArrayAlmostEqual(slab_from_gen.cart_coords, slab_from_trans.cart_coords)
def test_transform(self): s = Structure.from_spacegroup("Fm-3m", Lattice.cubic(5.69169), ["Na", "Cl"], [[0, 0, 0], [0, 0, 0.5]]) profile = dict(Na=dict(r=0.3, w=0.9), Cl=dict(r=0.7, w=3.0)) s *= [2, 2, 2] structures = [s] * 10 for s in structures: n = np.random.randint(4) inds = np.random.randint(16, size=n) s.remove_sites(inds) bc_atom = BispectrumCoefficients(rcutfac=5, twojmax=3, element_profile=profile, quadratic=False, pot_fit=False) df_atom = bc_atom.transform(structures) for i, s in enumerate(structures): df_s = df_atom.xs(i, level="input_index") self.assertEqual(df_s.shape, (len(s), 8)) self.assertTrue(df_s.equals(bc_atom.transform_one(s))) bc_pot = BispectrumCoefficients(rcutfac=5, twojmax=3, element_profile=profile, quadratic=False, pot_fit=True, include_stress=True) df_pot = bc_pot.transform(structures) for i, s in enumerate(structures): df_s = df_pot.xs(i, level="input_index") self.assertEqual(df_s.shape, (1 + len(s) * 3 + 6, 18)) self.assertTrue(df_s.equals(bc_pot.transform_one(s))) sna = df_s.iloc[0] for specie in ["Na", "Cl"]: self.assertAlmostEqual( sna[specie, "n"], s.composition.fractional_composition[specie]) np.testing.assert_array_equal(df_s[specie, "n"][1:], np.zeros(len(s) * 3 + 6))
def setUp(self): with open(os.path.join(test_dir, 'test_toec_data.json')) as f: self.data_dict = json.load(f) self.strains = [Strain(sm) for sm in self.data_dict['strains']] self.pk_stresses = [Stress(d) for d in self.data_dict['pk_stresses']] self.c2 = self.data_dict["C2_raw"] self.c3 = self.data_dict["C3_raw"] self.exp = ElasticTensorExpansion.from_voigt([self.c2, self.c3]) self.cu = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.623), ["Cu"], [[0]*3]) indices = [(0, 0), (0, 1), (3, 3)] values = [167.8, 113.5, 74.5] cu_c2 = ElasticTensor.from_values_indices(values, indices, structure=self.cu, populate=True) indices = [(0, 0, 0), (0, 0, 1), (0, 1, 2), (0, 3, 3), (0, 5, 5), (3, 4, 5)] values = [-1507., -965., -71., -7., -901., 45.] cu_c3 = Tensor.from_values_indices(values, indices, structure=self.cu, populate=True) self.exp_cu = ElasticTensorExpansion([cu_c2, cu_c3]) cu_c4 = Tensor.from_voigt(self.data_dict["Cu_fourth_order"]) self.exp_cu_4 = ElasticTensorExpansion([cu_c2, cu_c3, cu_c4])
def test_describe(self): s = Structure.from_spacegroup(225, Lattice.cubic(5.69169), ["Na", "Cl"], [[0, 0, 0], [0, 0, 0.5]]) profile = dict(Na=dict(r=0.5, w=1.0), Cl=dict(r=0.5, w=0.8)) bc = BispectrumCoefficients(rcutfac=5, twojmax=4, element_profile=profile, diagonalstyle=3) df = bc.describe(s) self.assertAlmostEqual(df.loc[0, "0-0-0"], 62.9328) self.assertTupleEqual(df.shape, (len(s), len(bc.subscripts))) s *= [2, 2, 2] structures = [s] * 10 for s in structures: n = np.random.randint(4) inds = np.random.randint(16, size=n) s.remove_sites(inds) df_all = bc.describe_all(structures) i = random.randint(0, 9) df_s = df_all.xs(i, level="input_index") self.assertEqual(df_s.shape[0], len(structures[i])) self.assertTrue(df_s.equals(bc.describe(structures[i])))