Ejemplo n.º 1
0
 def setUp(self):
     p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.Li2O'),
                          check_for_POTCAR=False)
     s1 = p.structure
     p = Poscar.from_file(os.path.join(test_dir, 'CONTCAR.Li2O'),
                          check_for_POTCAR=False)
     s2 = p.structure
     self.analyzer = RelaxationAnalyzer(s1, s2)
Ejemplo n.º 2
0
 def test_write(self):
     filepath = os.path.join(test_dir, 'POSCAR')
     poscar = Poscar.from_file(filepath)
     tempfname = "POSCAR.testing"
     poscar.write_file(tempfname)
     p = Poscar.from_file(tempfname)
     self.assertArrayAlmostEqual(poscar.structure.lattice.abc,
                                 p.structure.lattice.abc, 5)
     os.remove(tempfname)
def run_aconvasp_command(command, structure):
    """
    Helper function for calling aconvasp with different arguments
    """
    poscar = Poscar(structure)
    p = subprocess.Popen(command, stdout=subprocess.PIPE,
                         stdin=subprocess.PIPE,
                         stderr=subprocess.PIPE)
    output = p.communicate(input=poscar.get_string())
    return output
Ejemplo n.º 4
0
    def test_init(self):
        filepath = os.path.join(test_dir, 'POSCAR')
        poscar = Poscar.from_file(filepath)
        comp = poscar.structure.composition
        self.assertEqual(comp, Composition("Fe4P4O16"))

        #Vasp 4 type with symbols at the end.
        poscar_string = """Test1
1.0
3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
1 1
direct
0.000000 0.000000 0.000000 Si
0.750000 0.500000 0.750000 F
"""
        poscar = Poscar.from_string(poscar_string)
        self.assertEqual(poscar.structure.composition, Composition("SiF"))

        poscar_string = ""
        self.assertRaises(ValueError, Poscar.from_string, poscar_string)

        #Vasp 4 tyle file with default names, i.e. no element symbol found.
        poscar_string = """Test2
1.0
3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
1 1
direct
0.000000 0.000000 0.000000
0.750000 0.500000 0.750000
"""
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            poscar = Poscar.from_string(poscar_string)
        self.assertEqual(poscar.structure.composition, Composition("HHe"))

        #Vasp 4 tyle file with default names, i.e. no element symbol found.
        poscar_string = """Test3
1.0
3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
1 1
Selective dynamics
direct
0.000000 0.000000 0.000000 T T T Si
0.750000 0.500000 0.750000 F F F O
"""
        poscar = Poscar.from_string(poscar_string)
        self.assertEqual(poscar.selective_dynamics, [[True, True, True],
                                                     [False, False, False]])
        self.selective_poscar = poscar
Ejemplo n.º 5
0
def run_aconvasp_command(command, structure):
    """
    Helper function for calling aconvasp with different arguments
    """
    poscar = Poscar(structure)
    p = subprocess.Popen(command,
                         stdout=subprocess.PIPE,
                         stdin=subprocess.PIPE,
                         stderr=subprocess.PIPE)
    output = p.communicate(input=poscar.get_string())
    return output
Ejemplo n.º 6
0
 def plot_images(self, outfile):
     """
     Generates a POSCAR with the calculated diffusion path with respect to the first endpoint.
     :param outfile: Output file for the POSCAR
     """
     sum_struct = self.__images[0].sites
     for image in self.__images:
         for site_i in self.__relax_sites:
             sum_struct.append(PeriodicSite(image.sites[site_i].specie, image.sites[site_i].frac_coords,
                                            self.__images[0].lattice, to_unit_cell=True, coords_are_cartesian=False))
     sum_struct = Structure.from_sites(sum_struct, validate_proximity=False)
     p = Poscar(sum_struct)
     p.write_file(outfile)
Ejemplo n.º 7
0
    def test_str(self):
        si = 14
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])

        #Silicon structure for testing.
        latt = [[3.8401979337, 0.00, 0.00],
                [1.9200989668, 3.3257101909, 0.00],
                [0.00, -2.2171384943, 3.1355090603]]
        struct = Structure(latt, [si, si], coords)
        poscar = Poscar(struct)
        expected_str = '''Si2
1.0
3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
Si
2
direct
0.000000 0.000000 0.000000 Si
0.750000 0.500000 0.750000 Si
'''

        self.assertEquals(str(poscar), expected_str, "Wrong POSCAR output!")

        #Vasp 4 type with symbols at the end.
        poscar_string = """Test1
1.0
-3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
1 1
direct
0.000000 0.000000 0.000000 Si
0.750000 0.500000 0.750000 F
"""

        expected = """Test1
1.0
3.840198 -0.000000 -0.000000
-1.920099 -3.325710 -0.000000
-0.000000 2.217138 -3.135509
Si F
1 1
direct
0.000000 0.000000 0.000000 Si
0.750000 0.500000 0.750000 F
"""
        poscar = Poscar.from_string(poscar_string)
        self.assertEqual(str(poscar), expected)
Ejemplo n.º 8
0
    def test_init(self):
        filepath = os.path.join(test_dir, 'POSCAR')
        poscar = Poscar.from_file(filepath)
        comp = poscar.structure.composition
        self.assertEqual(comp, Composition.from_formula("Fe4P4O16"))

        #Vasp 4 type with symbols at the end.
        poscar_string = """Test1
1.0
3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
1 1
direct
0.000000 0.000000 0.000000 Si
0.750000 0.500000 0.750000 F
"""
        poscar = Poscar.from_string(poscar_string)
        self.assertEqual(poscar.structure.composition, Composition("SiF"))

        #Vasp 4 tyle file with default names, i.e. no element symbol found.
        poscar_string = """Test2
1.0
3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
1 1
direct
0.000000 0.000000 0.000000
0.750000 0.500000 0.750000
"""
        poscar = Poscar.from_string(poscar_string)
        self.assertEqual(poscar.structure.composition, Composition("HHe"))

        #Vasp 4 tyle file with default names, i.e. no element symbol found.
        poscar_string = """Test3
1.0
3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
1 1
Selective dynamics
direct
0.000000 0.000000 0.000000 T T T Si
0.750000 0.500000 0.750000 F F F O
"""
        poscar = Poscar.from_string(poscar_string)
        self.assertEqual(poscar.selective_dynamics, [[True, True, True],
                                                     [False, False, False]])
        self.selective_poscar = poscar
    def test_apply_transformation(self):
        trans = MagOrderingTransformation({"Fe": 5})
        p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.LiFePO4'),
                             check_for_POTCAR=False)
        s = p.structure
        alls = trans.apply_transformation(s, 10)
        self.assertEqual(len(alls), 3)
        f = SymmetryFinder(alls[0]["structure"], 0.1)
        self.assertEqual(f.get_spacegroup_number(), 31)

        model = IsingModel(5, 5)
        trans = MagOrderingTransformation({"Fe": 5},
                                          energy_model=model)
        alls2 = trans.apply_transformation(s, 10)
        #Ising model with +J penalizes similar neighbor magmom.
        self.assertNotEqual(alls[0]["structure"], alls2[0]["structure"])
        self.assertEqual(alls[0]["structure"], alls2[2]["structure"])

        from pymatgen.io.smartio import read_structure
        s = read_structure(os.path.join(test_dir, 'Li2O.cif'))
        #Li2O doesn't have magnetism of course, but this is to test the
        # enumeration.
        trans = MagOrderingTransformation({"Li+": 1}, max_cell_size=3)
        alls = trans.apply_transformation(s, 100)
        self.assertEqual(len(alls), 10)
Ejemplo n.º 10
0
    def test_init_from_structure(self):
        filepath = os.path.join(test_dir, 'POSCAR')
        poscar = Poscar.from_file(filepath)
        struct = poscar.structure
        xyz = XYZ(struct)
        ans = """24
Fe4 P4 O16
Fe 2.277347 4.550379 2.260125
Fe 2.928536 1.516793 4.639870
Fe 7.483231 4.550379 0.119620
Fe 8.134420 1.516793 2.499364
P 0.985089 1.516793 1.990624
P 4.220794 4.550379 4.370369
P 6.190973 1.516793 0.389120
P 9.426677 4.550379 2.768865
O 0.451582 4.550379 3.365614
O 1.006219 1.516793 3.528306
O 1.725331 0.279529 1.358282
O 1.725331 2.754057 1.358282
O 3.480552 3.313115 3.738027
O 3.480552 5.787643 3.738027
O 4.199665 4.550379 1.148562
O 4.754301 1.516793 0.985870
O 5.657466 4.550379 3.773620
O 6.212102 1.516793 3.610928
O 6.931215 0.279529 1.021463
O 6.931215 2.754057 1.021463
O 8.686436 3.313115 3.401208
O 8.686436 5.787643 3.401208
O 9.405548 4.550379 1.231183
O 9.960184 1.516793 1.393875"""
        self.assertEqual(str(xyz), ans)
 def test_ferrimagnetic(self):
     trans = MagOrderingTransformation({"Fe": 5}, 0.75, max_cell_size=1)
     p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.LiFePO4'),
                          check_for_POTCAR=False)
     s = p.structure
     alls = trans.apply_transformation(s, 10)
     self.assertEqual(len(alls), 2)
Ejemplo n.º 12
0
    def test_apply_transformations_best_first(self):

        p = Poscar.from_file(os.path.join(test_dir, "POSCAR.LiFePO4"), check_for_POTCAR=False)
        t1 = OxidationStateDecorationTransformation({"Li": 1, "Fe": 2, "P": 5, "O": -2})
        s = t1.apply_transformation(p.structure)
        t = PartialRemoveSpecieTransformation("Li+", 0.5, PartialRemoveSpecieTransformation.ALGO_BEST_FIRST)
        self.assertEqual(len(t.apply_transformation(s)), 26)
Ejemplo n.º 13
0
 def test_get_structure(self):
     if not aio.ase_loaded:
         raise SkipTest("ASE not present. Skipping...")
     p = Poscar.from_file(os.path.join(test_dir, 'POSCAR'))
     atoms = aio.AseAtomsAdaptor.get_atoms(p.structure)
     self.assertEqual(
         aio.AseAtomsAdaptor.get_structure(atoms).formula, "Fe4 P4 O16")
    def test_apply_transformation(self):
        enum_trans = EnumerateStructureTransformation(refine_structure=True)
        p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.LiFePO4'),
                             check_for_POTCAR=False)
        struct = p.structure
        expected_ans = [1, 3, 1]
        for i, frac in enumerate([0.25, 0.5, 0.75]):
            trans = SubstitutionTransformation({'Fe': {'Fe': frac}})
            s = trans.apply_transformation(struct)
            oxitrans = OxidationStateDecorationTransformation({
                'Li': 1,
                'Fe': 2,
                'P': 5,
                'O': -2
            })
            s = oxitrans.apply_transformation(s)
            alls = enum_trans.apply_transformation(s, 100)
            self.assertEquals(len(alls), expected_ans[i])
            self.assertIsInstance(trans.apply_transformation(s), Structure)
            for s in alls:
                self.assertIn("energy", s)

        #make sure it works for non-oxidation state decorated structure
        trans = SubstitutionTransformation({'Fe': {'Fe': 0.5}})
        s = trans.apply_transformation(struct)
        alls = enum_trans.apply_transformation(s, 100)
        self.assertEquals(len(alls), 3)
        self.assertIsInstance(trans.apply_transformation(s), Structure)
        for s in alls:
            self.assertNotIn("energy", s)
Ejemplo n.º 15
0
    def test_init_from_structure(self):
        filepath = os.path.join(test_dir, 'POSCAR')
        poscar = Poscar.from_file(filepath)
        struct = poscar.structure
        xyz = XYZ(struct)
        ans = """24
Fe4 P4 O16
Fe 2.277347 4.550379 2.260125
Fe 2.928536 1.516793 4.639870
Fe 7.483231 4.550379 0.119620
Fe 8.134420 1.516793 2.499364
P 0.985089 1.516793 1.990624
P 4.220794 4.550379 4.370369
P 6.190973 1.516793 0.389120
P 9.426677 4.550379 2.768865
O 0.451582 4.550379 3.365614
O 1.006219 1.516793 3.528306
O 1.725331 0.279529 1.358282
O 1.725331 2.754057 1.358282
O 3.480552 3.313115 3.738027
O 3.480552 5.787643 3.738027
O 4.199665 4.550379 1.148562
O 4.754301 1.516793 0.985870
O 5.657466 4.550379 3.773620
O 6.212102 1.516793 3.610928
O 6.931215 0.279529 1.021463
O 6.931215 2.754057 1.021463
O 8.686436 3.313115 3.401208
O 8.686436 5.787643 3.401208
O 9.405548 4.550379 1.231183
O 9.960184 1.516793 1.393875"""
        self.assertEqual(str(xyz), ans)
Ejemplo n.º 16
0
    def run_task(self, fw_spec):
        chgcar_start = False
        # read the VaspInput from the previous run

        poscar = Poscar.from_file(zpath('POSCAR'))
        incar = Incar.from_file(zpath('INCAR'))

        # figure out what GGA+U values to use and override them
        # LDAU values to use
        mpvis = MPVaspInputSet()
        ggau_incar = mpvis.get_incar(poscar.structure).to_dict
        incar_updates = {k: ggau_incar[k] for k in ggau_incar.keys() if 'LDAU' in k}

        for k in ggau_incar:
            # update any parameters not set explicitly in previous INCAR
            if k not in incar and k in ggau_incar:
                incar_updates[k] = ggau_incar[k]

        incar.update(incar_updates)  # override the +U keys


        # start from the CHGCAR of previous run
        if os.path.exists('CHGCAR'):
            incar['ICHARG'] = 1
            chgcar_start = True

        # write back the new INCAR to the current directory
        incar.write_file('INCAR')
        return FWAction(stored_data={'chgcar_start': chgcar_start})
Ejemplo n.º 17
0
    def test_static_constructors(self):
        kpoints = Kpoints.gamma_automatic([3, 3, 3], [0, 0, 0])
        self.assertEqual(kpoints.style, "Gamma")
        self.assertEqual(kpoints.kpts, [[3, 3, 3]])
        kpoints = Kpoints.monkhorst_automatic([2, 2, 2], [0, 0, 0])
        self.assertEqual(kpoints.style, "Monkhorst")
        self.assertEqual(kpoints.kpts, [[2, 2, 2]])
        kpoints = Kpoints.automatic(100)
        self.assertEqual(kpoints.style, "Automatic")
        self.assertEqual(kpoints.kpts, [[100]])
        filepath = os.path.join(test_dir, 'POSCAR')
        poscar = Poscar.from_file(filepath)
        kpoints = Kpoints.automatic_density(poscar.structure, 500)
        self.assertEqual(kpoints.kpts, [[2, 4, 4]])
        self.assertEqual(kpoints.style, "Monkhorst")
        kpoints = Kpoints.automatic_density(poscar.structure, 500, True)
        self.assertEqual(kpoints.style, "Gamma")
        kpoints = Kpoints.automatic_density_by_vol(poscar.structure, 1000)
        self.assertEqual(kpoints.kpts, [[6, 11, 13]])
        self.assertEqual(kpoints.style, "Gamma")

        s = poscar.structure
        s.make_supercell(3)
        kpoints = Kpoints.automatic_density(s, 500)
        self.assertEqual(kpoints.kpts, [[1, 1, 1]])
        self.assertEqual(kpoints.style, "Gamma")
 def test_ferrimagnetic(self):
     trans = MagOrderingTransformation({"Fe": 5}, 0.75, max_cell_size=1)
     p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.LiFePO4'),
                          check_for_POTCAR=False)
     s = p.structure
     alls = trans.apply_transformation(s, 10)
     self.assertEqual(len(alls), 2)
Ejemplo n.º 19
0
 def test_get_structure(self):
     if not aio.ase_loaded:
         raise SkipTest("ASE not present. Skipping...")
     p = Poscar.from_file(os.path.join(test_dir, 'POSCAR'))
     atoms = aio.AseAtomsAdaptor.get_atoms(p.structure)
     self.assertEqual(aio.AseAtomsAdaptor.get_structure(atoms).formula,
                      "Fe4 P4 O16")
Ejemplo n.º 20
0
    def run_task(self, fw_spec):
        chgcar_start = False
        # read the VaspInput from the previous run

        poscar = Poscar.from_file(zpath('POSCAR'))
        incar = Incar.from_file(zpath('INCAR'))

        # figure out what GGA+U values to use and override them
        # LDAU values to use
        mpvis = MPVaspInputSet()
        ggau_incar = mpvis.get_incar(poscar.structure).to_dict
        incar_updates = {
            k: ggau_incar[k]
            for k in ggau_incar.keys() if 'LDAU' in k
        }

        for k in ggau_incar:
            # update any parameters not set explicitly in previous INCAR
            if k not in incar and k in ggau_incar:
                incar_updates[k] = ggau_incar[k]

        incar.update(incar_updates)  # override the +U keys

        # start from the CHGCAR of previous run
        if os.path.exists('CHGCAR'):
            incar['ICHARG'] = 1
            chgcar_start = True

        # write back the new INCAR to the current directory
        incar.write_file('INCAR')
        return FWAction(stored_data={'chgcar_start': chgcar_start})
Ejemplo n.º 21
0
 def test_get_energy_tersoff(self):
     p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.Al12O18'),
                          check_for_POTCAR=False)
     structure = p.structure
     enrgy = get_energy_tersoff(structure)
     self.assertIsInstance(enrgy, float)
     print "tersoff energy", enrgy
Ejemplo n.º 22
0
 def test_from_md_run(self):
     #Parsing from an MD type run with velocities
     p = Poscar.from_file(os.path.join(test_dir, "CONTCAR.MD"),
                          check_for_POTCAR=False)
     self.assertAlmostEqual(np.sum(np.array(p.velocities)), 0.0065417961324)
     self.assertEqual(p.predictor_corrector[0][0], 1)
     self.assertEqual(p.predictor_corrector[1][0], 2)
    def test_apply_transformation(self):
        enum_trans = EnumerateStructureTransformation(refine_structure=True)
        p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.LiFePO4'),
                             check_for_POTCAR=False)
        struct = p.structure
        expected_ans = [1, 3, 1]
        for i, frac in enumerate([0.25, 0.5, 0.75]):
            trans = SubstitutionTransformation({'Fe': {'Fe': frac}})
            s = trans.apply_transformation(struct)
            oxitrans = OxidationStateDecorationTransformation({'Li': 1,
                                                               'Fe': 2,
                                                               'P': 5,
                                                               'O': -2})
            s = oxitrans.apply_transformation(s)
            alls = enum_trans.apply_transformation(s, 100)
            self.assertEquals(len(alls), expected_ans[i])
            self.assertIsInstance(trans.apply_transformation(s), Structure)
            for s in alls:
                self.assertIn("energy", s)

        #make sure it works for non-oxidation state decorated structure
        trans = SubstitutionTransformation({'Fe': {'Fe': 0.5}})
        s = trans.apply_transformation(struct)
        alls = enum_trans.apply_transformation(s, 100)
        self.assertEquals(len(alls), 3)
        self.assertIsInstance(trans.apply_transformation(s), Structure)
        for s in alls:
            self.assertNotIn("energy", s)
Ejemplo n.º 24
0
    def setUp(self):
        filepath = os.path.join(test_dir, 'POSCAR')
        poscar = Poscar.from_file(filepath)
        self.struct = poscar.structure

        self.mitparamset = MITVaspInputSet()
        self.mitparamset_unsorted = MITVaspInputSet(sort_structure=False)
        self.mithseparamset = MITHSEVaspInputSet()
        self.paramset = MPVaspInputSet()
        self.userparamset = MPVaspInputSet(
            user_incar_settings={'MAGMOM': {
                "Fe": 10,
                "S": -5,
                "Mn3+": 100
            }})
        self.mitggaparam = MITGGAVaspInputSet()
        self.mpstaticparamset = MPStaticVaspInputSet()
        self.mpnscfparamsetu = MPNonSCFVaspInputSet({"NBANDS": 50},
                                                    mode="Uniform")
        self.mpnscfparamsetl = MPNonSCFVaspInputSet({"NBANDS": 60},
                                                    mode="Line")
        self.mphseparamset = MPHSEVaspInputSet()
        self.mpbshseparamsetl = MPBSHSEVaspInputSet(mode="Line")
        self.mpbshseparamsetu = MPBSHSEVaspInputSet(
            mode="Uniform", added_kpoints=[[0.5, 0.5, 0.0]])
        self.mpdielparamset = MPStaticDielectricDFPTVaspInputSet()
Ejemplo n.º 25
0
 def test_from_md_run(self):
     #Parsing from an MD type run with velocities
     p = Poscar.from_file(os.path.join(test_dir, "CONTCAR.MD"),
                          check_for_POTCAR=False)
     self.assertAlmostEqual(np.sum(np.array(p.velocities)), 0.0065417961324)
     self.assertEqual(p.predictor_corrector[0][0], 1)
     self.assertEqual(p.predictor_corrector[1][0], 2)
Ejemplo n.º 26
0
 def test_apply_transformation(self):
     p = Poscar.from_file(os.path.join(test_dir, "POSCAR.LiFePO4"), check_for_POTCAR=False)
     t = AutoOxiStateDecorationTransformation()
     s = t.apply_transformation(p.structure)
     expected_oxi = {"Li": 1, "P": 5, "O": -2, "Fe": 2}
     for site in s:
         self.assertEqual(site.specie.oxi_state, expected_oxi[site.specie.symbol])
Ejemplo n.º 27
0
 def test_get_energy_tersoff(self):
     p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.Al12O18'),
                          check_for_POTCAR=False)
     structure = p.structure
     enrgy = get_energy_tersoff(structure)
     self.assertIsInstance(enrgy, float)
     print "tersoff energy", enrgy
Ejemplo n.º 28
0
def parse_vasp(groupdireclist, args):

    data_to_csv = []

    default_energies = not (args.get_energies or args.ion_list or args.ion_avg_list)

    templatestructure = []

    if args.template:
        for (parent, subdirs, files) in os.walk(args.strtemp[0]):
            if 'POSCAR' in files:
                filepath = glob.glob(os.path.join(parent,"POSCAR"))
                poscarfile = Poscar.from_file(filepath[0])
                templatestructure = poscarfile.structure



    if args.get_energies or default_energies:
        for d in groupdireclist:
            groupdata= get_energies(d, args.reanalyze, args.verbose,
                         args.detailed, args.sort[0],args.formulaunit,args.debug,args.hull,args.threshold, args, templatestructure)
            data_to_csv.extend(groupdata)



    output_CSV(data_to_csv,args)
Ejemplo n.º 29
0
 def plot_images(self, outfile):
     """
     Generates a POSCAR with the calculated diffusion path with respect to the first endpoint.
     :param outfile: Output file for the POSCAR
     """
     sum_struct = self.__images[0].sites
     for image in self.__images:
         for site_i in self.__relax_sites:
             sum_struct.append(
                 PeriodicSite(image.sites[site_i].specie,
                              image.sites[site_i].frac_coords,
                              self.__images[0].lattice,
                              to_unit_cell=True,
                              coords_are_cartesian=False))
     sum_struct = Structure.from_sites(sum_struct, validate_proximity=False)
     p = Poscar(sum_struct)
     p.write_file(outfile)
Ejemplo n.º 30
0
    def test_to_from_dict(self):
        poscar_string = """Test3
1.0
3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
1 1
Selective dynamics
direct
0.000000 0.000000 0.000000 T T T Si
0.750000 0.500000 0.750000 F F F O"""
        poscar = Poscar.from_string(poscar_string)
        d = poscar.to_dict
        poscar2 = Poscar.from_dict(d)
        self.assertEqual(poscar2.comment, "Test3")
        self.assertTrue(all(poscar2.selective_dynamics[0]))
        self.assertFalse(all(poscar2.selective_dynamics[1]))
Ejemplo n.º 31
0
 def test_get_atoms(self):
     if not aio.ase_loaded:
         raise SkipTest("ASE not present. Skipping...")
     p = Poscar.from_file(os.path.join(test_dir, 'POSCAR'))
     structure = p.structure
     atoms = aio.AseAtomsAdaptor.get_atoms(structure)
     ase_composition = Composition.from_formula(atoms.get_name())
     self.assertEqual(ase_composition, structure.composition)
Ejemplo n.º 32
0
    def test_to_from_dict(self):
        poscar_string = """Test3
1.0
3.840198 0.000000 0.000000
1.920099 3.325710 0.000000
0.000000 -2.217138 3.135509
1 1
Selective dynamics
direct
0.000000 0.000000 0.000000 T T T Si
0.750000 0.500000 0.750000 F F F O"""
        poscar = Poscar.from_string(poscar_string)
        d = poscar.to_dict
        poscar2 = Poscar.from_dict(d)
        self.assertEqual(poscar2.comment, "Test3")
        self.assertTrue(all(poscar2.selective_dynamics[0]))
        self.assertFalse(all(poscar2.selective_dynamics[1]))
Ejemplo n.º 33
0
 def test_get_atoms(self):
     if not aio.ase_loaded:
         raise SkipTest("ASE not present. Skipping...")
     p = Poscar.from_file(os.path.join(test_dir, 'POSCAR'))
     structure = p.structure
     atoms = aio.AseAtomsAdaptor.get_atoms(structure)
     ase_composition = Composition(atoms.get_name())
     self.assertEqual(ase_composition, structure.composition)
Ejemplo n.º 34
0
    def test_CifWriter(self):
        filepath = os.path.join(test_dir, 'POSCAR')
        poscar = Poscar.from_file(filepath)
        writer = CifWriter(poscar.structure, find_spacegroup=True)
        ans = """#generated using pymatgen
data_FePO4
_symmetry_space_group_name_H-M   Pnma
_cell_length_a   10.41176687
_cell_length_b   6.06717188
_cell_length_c   4.75948954
_cell_angle_alpha   90.00000000
_cell_angle_beta   90.00000000
_cell_angle_gamma   90.00000000
_symmetry_Int_Tables_number   62
_chemical_formula_structural   FePO4
_chemical_formula_sum   'Fe4 P4 O16'
_cell_volume   300.65685512
_cell_formula_units_Z   4
loop_
  _symmetry_equiv_pos_site_id
  _symmetry_equiv_pos_as_xyz
   1  'x, y, z'
loop_
  _atom_site_type_symbol
  _atom_site_label
  _atom_site_symmetry_multiplicity
  _atom_site_fract_x
  _atom_site_fract_y
  _atom_site_fract_z
  _atom_site_occupancy
  Fe  Fe1  1  0.218728  0.750000  0.474867  1
  Fe  Fe2  1  0.281272  0.250000  0.974867  1
  Fe  Fe3  1  0.718728  0.750000  0.025133  1
  Fe  Fe4  1  0.781272  0.250000  0.525133  1
  P  P5  1  0.094613  0.250000  0.418243  1
  P  P6  1  0.405387  0.750000  0.918243  1
  P  P7  1  0.594613  0.250000  0.081757  1
  P  P8  1  0.905387  0.750000  0.581757  1
  O  O9  1  0.043372  0.750000  0.707138  1
  O  O10  1  0.096642  0.250000  0.741320  1
  O  O11  1  0.165710  0.046072  0.285384  1
  O  O12  1  0.165710  0.453928  0.285384  1
  O  O13  1  0.334290  0.546072  0.785384  1
  O  O14  1  0.334290  0.953928  0.785384  1
  O  O15  1  0.403358  0.750000  0.241320  1
  O  O16  1  0.456628  0.250000  0.207138  1
  O  O17  1  0.543372  0.750000  0.792862  1
  O  O18  1  0.596642  0.250000  0.758680  1
  O  O19  1  0.665710  0.046072  0.214616  1
  O  O20  1  0.665710  0.453928  0.214616  1
  O  O21  1  0.834290  0.546072  0.714616  1
  O  O22  1  0.834290  0.953928  0.714616  1
  O  O23  1  0.903358  0.750000  0.258680  1
  O  O24  1  0.956628  0.250000  0.292862  1

"""
        for l1, l2 in zip(str(writer).split("\n"), ans.split("\n")):
            self.assertEqual(l1.strip(), l2.strip())
Ejemplo n.º 35
0
    def test_get_lattice_from_lattice_type(self):
        cif_structure = """#generated using pymatgen
data_FePO4
_symmetry_space_group_name_H-M   Pnma
_cell_length_a   10.41176687
_cell_length_b   6.06717188
_cell_length_c   4.75948954
_chemical_formula_structural   FePO4
_chemical_formula_sum   'Fe4 P4 O16'
_cell_volume   300.65685512
_cell_formula_units_Z   4
_symmetry_cell_setting Orthorhombic
loop_
  _symmetry_equiv_pos_site_id
  _symmetry_equiv_pos_as_xyz
   1  'x, y, z'
loop_
  _atom_site_type_symbol
  _atom_site_label
  _atom_site_symmetry_multiplicity
  _atom_site_fract_x
  _atom_site_fract_y
  _atom_site_fract_z
  _atom_site_occupancy
  Fe  Fe1  1  0.218728  0.750000  0.474867  1
  Fe  Fe2  1  0.281272  0.250000  0.974867  1
  Fe  Fe3  1  0.718728  0.750000  0.025133  1
  Fe  Fe4  1  0.781272  0.250000  0.525133  1
  P  P5  1  0.094613  0.250000  0.418243  1
  P  P6  1  0.405387  0.750000  0.918243  1
  P  P7  1  0.594613  0.250000  0.081757  1
  P  P8  1  0.905387  0.750000  0.581757  1
  O  O9  1  0.043372  0.750000  0.707138  1
  O  O10  1  0.096642  0.250000  0.741320  1
  O  O11  1  0.165710  0.046072  0.285384  1
  O  O12  1  0.165710  0.453928  0.285384  1
  O  O13  1  0.334290  0.546072  0.785384  1
  O  O14  1  0.334290  0.953928  0.785384  1
  O  O15  1  0.403358  0.750000  0.241320  1
  O  O16  1  0.456628  0.250000  0.207138  1
  O  O17  1  0.543372  0.750000  0.792862  1
  O  O18  1  0.596642  0.250000  0.758680  1
  O  O19  1  0.665710  0.046072  0.214616  1
  O  O20  1  0.665710  0.453928  0.214616  1
  O  O21  1  0.834290  0.546072  0.714616  1
  O  O22  1  0.834290  0.953928  0.714616  1
  O  O23  1  0.903358  0.750000  0.258680  1
  O  O24  1  0.956628  0.250000  0.292862  1

"""
        cp = CifParser.from_string(cif_structure)
        s_test = cp.get_structures(False)[0]
        filepath = os.path.join(test_dir, 'POSCAR')
        poscar = Poscar.from_file(filepath)
        s_ref = poscar.structure

        sm = StructureMatcher(stol=0.05, ltol=0.01, angle_tol=0.1)
        self.assertTrue(sm.fit(s_ref, s_test))
Ejemplo n.º 36
0
    def test_CifWriter(self):
        filepath = os.path.join(test_dir, 'POSCAR')
        poscar = Poscar.from_file(filepath)
        writer = CifWriter(poscar.structure, find_spacegroup=True)
        ans = """#generated using pymatgen
data_FePO4
_symmetry_space_group_name_H-M   Pnma
_cell_length_a   10.41176687
_cell_length_b   6.06717188
_cell_length_c   4.75948954
_cell_angle_alpha   90.00000000
_cell_angle_beta   90.00000000
_cell_angle_gamma   90.00000000
_symmetry_Int_Tables_number   62
_chemical_formula_structural   FePO4
_chemical_formula_sum   'Fe4 P4 O16'
_cell_volume   300.65685512
_cell_formula_units_Z   4
loop_
  _symmetry_equiv_pos_site_id
  _symmetry_equiv_pos_as_xyz
   1  'x, y, z'
loop_
  _atom_site_type_symbol
  _atom_site_label
  _atom_site_symmetry_multiplicity
  _atom_site_fract_x
  _atom_site_fract_y
  _atom_site_fract_z
  _atom_site_occupancy
  Fe  Fe1  1  0.218728  0.750000  0.474867  1
  Fe  Fe2  1  0.281272  0.250000  0.974867  1
  Fe  Fe3  1  0.718728  0.750000  0.025133  1
  Fe  Fe4  1  0.781272  0.250000  0.525133  1
  P  P5  1  0.094613  0.250000  0.418243  1
  P  P6  1  0.405387  0.750000  0.918243  1
  P  P7  1  0.594613  0.250000  0.081757  1
  P  P8  1  0.905387  0.750000  0.581757  1
  O  O9  1  0.043372  0.750000  0.707138  1
  O  O10  1  0.096642  0.250000  0.741320  1
  O  O11  1  0.165710  0.046072  0.285384  1
  O  O12  1  0.165710  0.453928  0.285384  1
  O  O13  1  0.334290  0.546072  0.785384  1
  O  O14  1  0.334290  0.953928  0.785384  1
  O  O15  1  0.403358  0.750000  0.241320  1
  O  O16  1  0.456628  0.250000  0.207138  1
  O  O17  1  0.543372  0.750000  0.792862  1
  O  O18  1  0.596642  0.250000  0.758680  1
  O  O19  1  0.665710  0.046072  0.214616  1
  O  O20  1  0.665710  0.453928  0.214616  1
  O  O21  1  0.834290  0.546072  0.714616  1
  O  O22  1  0.834290  0.953928  0.714616  1
  O  O23  1  0.903358  0.750000  0.258680  1
  O  O24  1  0.956628  0.250000  0.292862  1

"""
        for l1, l2 in zip(str(writer).split("\n"), ans.split("\n")):
            self.assertEqual(l1.strip(), l2.strip())
Ejemplo n.º 37
0
def get_prim_struct(structure):
    """
    Get standard primitive
    """
    output = run_aconvasp_command(["aconvasp", "--std_prim"], structure)
    if "ERROR" in output[1]:
        raise AconvaspError(output[1])
    tmp = Poscar.from_string(output[0])
    return {'struct': tmp.structure, 'comm': tmp.comment}
Ejemplo n.º 38
0
def get_conv_struct(structure):
    """
    Get a minkowski reduced structure
    """
    output = run_aconvasp_command(["aconvasp", "--std_conv"], structure)
    if "ERROR" in output[1]:
        raise AconvaspError(output[1])
    tmp = Poscar.from_string(output[0])
    return {'struct': tmp.structure, 'comm': tmp.comment}
Ejemplo n.º 39
0
    def _get_structures(self, num_structs):
        structs = []
        rs = subprocess.Popen(
            ["makestr.x", "struct_enum.out",
             str(0),
             str(num_structs - 1)],
            stdout=subprocess.PIPE,
            stdin=subprocess.PIPE,
            close_fds=True)
        rs.communicate()
        if len(self.ordered_sites) > 0:
            original_latt = self.ordered_sites[0].lattice
            # Need to strip sites of site_properties, which would otherwise
            # result in an index error. Hence Structure is reconstructed in
            # the next step.
            ordered_structure = Structure(
                original_latt,
                [site.species_and_occu for site in self.ordered_sites],
                [site.frac_coords for site in self.ordered_sites])
            inv_org_latt = np.linalg.inv(original_latt.matrix)

        for n in range(1, num_structs + 1):
            with open("vasp.{:06d}".format(n)) as f:
                data = f.read()
                data = re.sub("scale factor", "1", data)
                data = re.sub("(\d+)-(\d+)", r"\1 -\2", data)
                poscar = Poscar.from_string(data, self.index_species)
                sub_structure = poscar.structure
                #Enumeration may have resulted in a super lattice. We need to
                #find the mapping from the new lattice to the old lattice, and
                #perform supercell construction if necessary.
                new_latt = sub_structure.lattice

                sites = []

                if len(self.ordered_sites) > 0:
                    transformation = np.dot(new_latt.matrix, inv_org_latt)
                    transformation = [[int(round(cell)) for cell in row]
                                      for row in transformation]
                    logger.debug("Supercell matrix: {}".format(transformation))
                    s = Structure.from_sites(ordered_structure)
                    s.make_supercell(transformation)
                    sites.extend([site.to_unit_cell for site in s])
                    super_latt = sites[-1].lattice
                else:
                    super_latt = new_latt

                for site in sub_structure:
                    if site.specie.symbol != "X":  # We exclude vacancies.
                        sites.append(
                            PeriodicSite(site.species_and_occu,
                                         site.frac_coords,
                                         super_latt).to_unit_cell)
                structs.append(Structure.from_sites(sorted(sites)))

        logger.debug("Read in a total of {} structures.".format(num_structs))
        return structs
Ejemplo n.º 40
0
 def check(self):
     try:
         oszicar = Oszicar(self.output_filename)
         n = len(Poscar.from_file(self.input_filename).structure)
         max_dE = max([s['dE'] for s in oszicar.ionic_steps[1:]]) / n
         if max_dE > self.dE_threshold:
             return True
     except:
         return False
def get_prim_struct(structure):
    """
    Get standard primitive
    """
    output = run_aconvasp_command(["aconvasp", "--std_prim"], structure)
    if "ERROR" in output[1]:
        raise AconvaspError(output[1])
    tmp = Poscar.from_string(output[0])
    return {'struct': tmp.structure, 'comm': tmp.comment}
 def test_apply_transformation(self):
     p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.LiFePO4'),
                          check_for_POTCAR=False)
     t = AutoOxiStateDecorationTransformation()
     s = t.apply_transformation(p.structure)
     expected_oxi = {"Li": 1, "P": 5, "O":-2, "Fe": 2}
     for site in s:
         self.assertEqual(site.specie.oxi_state,
                          expected_oxi[site.specie.symbol])
Ejemplo n.º 43
0
    def get_incar(self, structure):
        incar = Incar()
        if self.sort_structure:
            structure = structure.get_sorted_structure()
        comp = structure.composition
        elements = sorted([el for el in comp.elements if comp[el] > 0],
                          key=lambda el: el.X)
        most_electroneg = elements[-1].symbol
        poscar = Poscar(structure)
        for key, setting in self.incar_settings.items():
            if key == "MAGMOM":
                mag = []
                for site in structure:
                    if hasattr(site, 'magmom'):
                        mag.append(site.magmom)
                    elif hasattr(site.specie, 'spin'):
                        mag.append(site.specie.spin)
                    elif str(site.specie) in setting:
                        mag.append(setting.get(str(site.specie)))
                    else:
                        mag.append(setting.get(site.specie.symbol, 0.6))
                incar[key] = mag
            elif key in ('LDAUU', 'LDAUJ', 'LDAUL'):
                if most_electroneg in setting.keys():
                    incar[key] = [
                        setting[most_electroneg].get(sym, 0)
                        for sym in poscar.site_symbols
                    ]
                else:
                    incar[key] = [0] * len(poscar.site_symbols)
            elif key == "EDIFF":
                incar[key] = float(setting) * structure.num_sites
            else:
                incar[key] = setting

        has_u = ("LDAUU" in incar and sum(incar['LDAUU']) > 0)
        if has_u:
            # modify LMAXMIX if LSDA+U and you have d or f electrons
            # note that if the user explicitly sets LMAXMIX in settings it will
            # override this logic.
            if 'LMAXMIX' not in self.incar_settings.keys():
                # contains f-electrons
                if any([el.Z > 56 for el in structure.composition]):
                    incar['LMAXMIX'] = 6
                # contains d-electrons
                elif any([el.Z > 20 for el in structure.composition]):
                    incar['LMAXMIX'] = 4
        else:
            for key in incar.keys():
                if key.startswith('LDAU'):
                    del incar[key]

        if self.set_nupdown:
            nupdown = sum([mag if mag > 0.6 else 0 for mag in incar['MAGMOM']])
            incar['NUPDOWN'] = nupdown

        return incar
def get_conv_struct(structure):
    """
    Get a minkowski reduced structure
    """
    output = run_aconvasp_command(["aconvasp", "--std_conv"], structure)
    if "ERROR" in output[1]:
        raise AconvaspError(output[1])
    tmp = Poscar.from_string(output[0])
    return {'struct': tmp.structure, 'comm': tmp.comment}
Ejemplo n.º 45
0
    def test_velocities(self):
        si = 14
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])

        # Silicon structure for testing.
        latt = [[3.8401979337, 0.00, 0.00], [1.9200989668, 3.3257101909, 0.00], [0.00, -2.2171384943, 3.1355090603]]
        struct = Structure(latt, [si, si], coords)
        poscar = Poscar(struct)
        poscar.set_temperature(900)

        v = np.array(poscar.velocities)

        for x in np.sum(v, axis=0):
            self.assertAlmostEqual(x, 0, 7, "Velocities initialized with a net momentum")

        temperature = struct[0].specie.atomic_mass * AMU_TO_KG * np.sum(v ** 2) / (3 * BOLTZMANN_CONST) * 1e10
        self.assertAlmostEqual(temperature, 900, 4, "Temperature instantiated incorrectly")
    def test_apply_transformations_best_first(self):

        p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.LiFePO4'),
                             check_for_POTCAR=False)
        t1 = OxidationStateDecorationTransformation({"Li": 1, "Fe": 2, "P": 5,
                                                     "O":-2})
        s = t1.apply_transformation(p.structure)
        t = PartialRemoveSpecieTransformation("Li+", 0.5,
                                              PartialRemoveSpecieTransformation.ALGO_BEST_FIRST)
        self.assertEqual(len(t.apply_transformation(s)), 26)
    def test_apply_transformations_complete_ranking(self):

        p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.LiFePO4'),
                             check_for_POTCAR=False)
        t1 = OxidationStateDecorationTransformation({"Li": 1, "Fe": 2, "P": 5,
                                                     "O":-2})
        s = t1.apply_transformation(p.structure)
        t = PartialRemoveSpecieTransformation("Li+", 0.5,
                                              PartialRemoveSpecieTransformation.ALGO_COMPLETE)
        self.assertEqual(len(t.apply_transformation(s, 10)), 6)
Ejemplo n.º 48
0
def buildPOSCAR(iat, fposcar="POSCAR"):
    """
    Build POSCAR file according to atom for wich CL calculation is required. The
    corresponding atom is placed in first position in the POSCAR.
    """
    from pymatgen.io.vaspio.vasp_input import Poscar
    poscar = Poscar.from_file(fposcar)

    site = poscar.structure.pop(iat)
    poscar.structure.insert(0, site.specie, site.frac_coords)
    poscar.write_file("POSCAR_CL.vasp")
Ejemplo n.º 49
0
    def _get_structures(self, num_structs):
        structs = []
        rs = subprocess.Popen(["makestr.x",
                               "struct_enum.out", str(0),
                               str(num_structs - 1)],
                              stdout=subprocess.PIPE,
                              stdin=subprocess.PIPE, close_fds=True)
        rs.communicate()
        if len(self.ordered_sites) > 0:
            original_latt = self.ordered_sites[0].lattice
            # Need to strip sites of site_properties, which would otherwise
            # result in an index error. Hence Structure is reconstructed in
            # the next step.
            ordered_structure = Structure(
                original_latt,
                [site.species_and_occu for site in self.ordered_sites],
                [site.frac_coords for site in self.ordered_sites])
            inv_org_latt = np.linalg.inv(original_latt.matrix)

        for n in range(1, num_structs + 1):
            with open("vasp.{:06d}".format(n)) as f:
                data = f.read()
                data = re.sub("scale factor", "1", data)
                data = re.sub("(\d+)-(\d+)", r"\1 -\2", data)
                poscar = Poscar.from_string(data, self.index_species)
                sub_structure = poscar.structure
                #Enumeration may have resulted in a super lattice. We need to
                #find the mapping from the new lattice to the old lattice, and
                #perform supercell construction if necessary.
                new_latt = sub_structure.lattice

                sites = []

                if len(self.ordered_sites) > 0:
                    transformation = np.dot(new_latt.matrix, inv_org_latt)
                    transformation = [[int(round(cell)) for cell in row]
                                      for row in transformation]
                    logger.debug("Supercell matrix: {}".format(transformation))
                    s = Structure.from_sites(ordered_structure)
                    s.make_supercell(transformation)
                    sites.extend([site.to_unit_cell for site in s])
                    super_latt = sites[-1].lattice
                else:
                    super_latt = new_latt

                for site in sub_structure:
                    if site.specie.symbol != "X":  # We exclude vacancies.
                        sites.append(PeriodicSite(site.species_and_occu,
                                                  site.frac_coords,
                                                  super_latt).to_unit_cell)
                structs.append(Structure.from_sites(sorted(sites)))

        logger.debug("Read in a total of {} structures.".format(num_structs))
        return structs
Ejemplo n.º 50
0
 def run_task(self, fw_spec):
     user_incar_settings= {"NPAR": 2}
     if self.line:
         MPNonSCFVaspInputSet.from_previous_vasp_run(os.getcwd(), mode="Line", copy_chgcar=False,
                                                     user_incar_settings=user_incar_settings,)
         kpath = HighSymmKpath(Poscar.from_file("POSCAR").structure)
         return FWAction(stored_data={"kpath": kpath.kpath,
                                      "kpath_name": kpath.name})
     else:
         MPNonSCFVaspInputSet.from_previous_vasp_run(os.getcwd(), mode="Uniform", copy_chgcar=False,
                              user_incar_settings=user_incar_settings)
         return FWAction()
Ejemplo n.º 51
0
    def setUp(self):
        filepath = os.path.join(test_dir, 'POSCAR')
        poscar = Poscar.from_file(filepath)
        self.struct = poscar.structure

        self.mitparamset = MITVaspInputSet()
        self.mithseparamset = MITHSEVaspInputSet()
        self.paramset = MaterialsProjectVaspInputSet()
        self.userparamset = MaterialsProjectVaspInputSet(
            {'MAGMOM': {"Fe": 10, "S": -5, "Mn3+": 100}}
        )
        self.mitggaparam = MITGGAVaspInputSet()
Ejemplo n.º 52
0
    def setUp(self):
        filepath = os.path.join(test_dir, 'POSCAR')
        p = Poscar.from_file(filepath)
        self.structure = p.structure
        bv = BVAnalyzer()
        valences = bv.get_valences(self.structure)
        el = [site.species_string for site in self.structure.sites]
        valence_dict = dict(zip(el, valences))
        self.rad_dict = {}
        for k, v in valence_dict.items():
            self.rad_dict[k] = Specie(k, v).ionic_radius

        assert len(self.rad_dict) == len(self.structure.composition)
Ejemplo n.º 53
0
 def test_static_constructors(self):
     kpoints = Kpoints.gamma_automatic([3, 3, 3], [0, 0, 0])
     self.assertEqual(kpoints.style, "Gamma")
     self.assertEqual(kpoints.kpts, [[3, 3, 3]])
     kpoints = Kpoints.monkhorst_automatic([2, 2, 2], [0, 0, 0])
     self.assertEqual(kpoints.style, "Monkhorst")
     self.assertEqual(kpoints.kpts, [[2, 2, 2]])
     kpoints = Kpoints.automatic(100)
     self.assertEqual(kpoints.style, "Automatic")
     self.assertEqual(kpoints.kpts, [[100]])
     filepath = os.path.join(test_dir, 'POSCAR')
     poscar = Poscar.from_file(filepath)
     kpoints = Kpoints.automatic_density(poscar.structure, 500)
     self.assertEqual(kpoints.kpts, [[2, 3, 4]])
Ejemplo n.º 54
0
    def test_velocities(self):
        si = 14
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])

        #Silicon structure for testing.
        latt = [[3.8401979337, 0.00, 0.00], [1.9200989668, 3.3257101909, 0.00],
                [0.00, -2.2171384943, 3.1355090603]]
        struct = Structure(latt, [si, si], coords)
        poscar = Poscar(struct)
        poscar.set_temperature(900)

        v = np.array(poscar.velocities)

        for x in np.sum(v, axis=0):
            self.assertAlmostEqual(
                x, 0, 7, 'Velocities initialized with a net momentum')

        temperature = struct[0].specie.atomic_mass * AMU_TO_KG * \
            np.sum(v ** 2) / (3 * BOLTZMANN_CONST) * 1e10
        self.assertAlmostEqual(temperature, 900, 4,
                               'Temperature instantiated incorrectly')
Ejemplo n.º 55
0
    def get_new_poscar_lines(self):
        """
        Pymatgen does not realize that decorated elements (species) should be
        treated as different sites in VASP.

        This routine hacks the poscar file (which has already been hacked to go from 5.x to 4.6)
        to include the correct number of distinct sites.
        """

        self.check_structure_is_modified()

        # get a poscar consistent with the internally modified structure
        poscar = Poscar(self.structure)

        lines = poscar.get_string(vasp4_compatible=True).split('\n')
        
        hack_line = ''
        for element, number in self.species_dict.items():
            hack_line += ' %i'%number

        lines[5] = hack_line

        return lines
Ejemplo n.º 56
0
 def setUp(self):
     p = Poscar.from_file(os.path.join(test_dir, 'POSCAR'))
     self.structure = p.structure
     self.sg = SpacegroupAnalyzer(self.structure, 0.001)
     self.disordered_structure = self.get_structure('Li10GeP2S12')
     self.disordered_sg = SpacegroupAnalyzer(self.disordered_structure,
                                             0.001)
     s = p.structure.copy()
     site = s[0]
     del s[0]
     s.append(site.species_and_occu, site.frac_coords)
     self.sg3 = SpacegroupAnalyzer(s, 0.001)
     graphite = self.get_structure('Graphite')
     graphite.add_site_property("magmom", [0.1] * len(graphite))
     self.sg4 = SpacegroupAnalyzer(graphite, 0.001)
Ejemplo n.º 57
0
 def setUp(self):
     filepath = os.path.join(test_dir, 'INCAR')
     incar = Incar.from_file(filepath)
     filepath = os.path.join(test_dir, 'POSCAR')
     poscar = Poscar.from_file(filepath)
     if "VASP_PSP_DIR" not in os.environ:
         test_potcar_dir = os.path.abspath(
             os.path.join(os.path.dirname(__file__), "..", "..", "..", "..",
                          "test_files"))
         os.environ["VASP_PSP_DIR"] = test_potcar_dir
     filepath = os.path.join(test_dir, 'POTCAR')
     potcar = Potcar.from_file(filepath)
     filepath = os.path.join(test_dir, 'KPOINTS.auto')
     kpoints = Kpoints.from_file(filepath)
     self.vinput = VaspInput(incar, kpoints, poscar, potcar)
Ejemplo n.º 58
0
    def test_init(self):
        filepath = os.path.join(test_dir, 'POSCAR')
        p = Poscar.from_file(filepath)
        original_s = p.structure
        s = original_s.copy()
        s.add_oxidation_state_by_element({"Li": 1, "Fe": 2, "P": 5, "O": -2})
        ham = EwaldSummation(s)
        self.assertAlmostEqual(ham.real_space_energy, -354.91294268, 4,
                               "Real space energy incorrect!")
        self.assertAlmostEqual(ham.reciprocal_space_energy, 25.475754801, 4)
        self.assertAlmostEqual(ham.point_energy, -790.463835033, 4,
                               "Point space energy incorrect!")
        self.assertAlmostEqual(ham.total_energy, -1119.90102291, 2,
                               "Total space energy incorrect!")
        self.assertAlmostEqual(ham.forces[0, 0], -1.98818620e-01, 4,
                               "Forces incorrect")
        self.assertAlmostEqual(sum(sum(abs(ham.forces))), 915.925354346, 4,
                               "Forces incorrect")
        self.assertAlmostEqual(sum(sum(ham.real_space_energy_matrix)),
                               -354.91294268, 4,
                               "Real space energy matrix incorrect!")
        self.assertAlmostEqual(sum(sum(ham.reciprocal_space_energy_matrix)),
                               25.475754801, 4,
                               "Reciprocal space energy matrix incorrect!")
        self.assertAlmostEqual(sum(ham.point_energy_matrix), -790.463835033, 4,
                               "Point space energy matrix incorrect!")
        self.assertAlmostEqual(sum(sum(ham.total_energy_matrix)),
                               -1119.90102291, 2,
                               "Total space energy matrix incorrect!")
        #note that forces are not individually tested, but should work fine.

        self.assertRaises(ValueError, EwaldSummation, original_s)
        #try sites with charge.
        charges = []
        for site in original_s:
            if site.specie.symbol == "Li":
                charges.append(1)
            elif site.specie.symbol == "Fe":
                charges.append(2)
            elif site.specie.symbol == "P":
                charges.append(5)
            else:
                charges.append(-2)

        original_s.add_site_property('charge', charges)
        ham2 = EwaldSummation(original_s)
        self.assertAlmostEqual(ham2.real_space_energy, -354.91294268, 4,
                               "Real space energy incorrect!")
Ejemplo n.º 59
0
 def setUp(self):
     filepath = os.path.join(test_dir, 'POSCAR')
     p = Poscar.from_file(filepath)
     self.structure = p.structure
     bv = BVAnalyzer()
     self.structure = bv.get_oxi_state_decorated_structure(self.structure)
     valences = bv.get_valences(self.structure)
     radii = []
     for i in range(len(valences)):
         el = self.structure.sites[i].specie.symbol
         radius = Specie(el, valences[i]).ionic_radius
         radii.append(radius)
     el = [site.species_string for site in self.structure.sites]
     self.rad_dict = dict(zip(el, radii))
     for el in self.rad_dict.keys():
         print((el, self.rad_dict[el].real))