How to use the pymatgen.io.vaspio.Poscar.from_file function in pymatgen

To help you get started, we’ve selected a few pymatgen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uw-cmg / MAST / test / structure_extensions_test / test_structure_extensions.py View on Github external
def test_interpolation(self):
        ep1 = pymatgen.io.vaspio.Poscar.from_file("POSCAR_ep1").structure
        ep2 = pymatgen.io.vaspio.Poscar.from_file("POSCAR_ep2").structure
        compare_im1 = pymatgen.io.vaspio.Poscar.from_file("POSCAR_im1").structure
        compare_im2 = pymatgen.io.vaspio.Poscar.from_file("POSCAR_im2").structure
        compare_im3 = pymatgen.io.vaspio.Poscar.from_file("POSCAR_im3").structure
        sxtend = StructureExtensions(struc_work1 = ep1, struc_work2 = ep2)
        slist = sxtend.do_interpolation(3)
        self.assertEqual(slist[0],ep1)
        self.assertEqual(slist[1],compare_im1)
        self.assertEqual(slist[2],compare_im2)
        self.assertEqual(slist[3],compare_im3)
        self.assertEqual(slist[4],ep2)
    def test_get_sd_array(self):
github uw-cmg / MAST / test / chop_test_write / test_writeingredient.py View on Github external
kdict['mast_neb_settings']['lines']=neblines
        ingdir = "writedir/neb_labelinit-labelfin"
        topmetad = MASTFile("files/top_metadata_neb")
        topmetad.to_file("writedir/metadata.txt")
        metad = MASTFile("files/metadata_neb")
        metad.to_file("%s/metadata.txt" % ingdir)
        unsorted_init = MASTFile("unsorted/parent_structure_labelinit")
        #unsorted_init = MASTFile("unsorted/parent_structure_labelinit_scrambled")
        unsorted_init.to_file("%s/parent_structure_labelinit" % ingdir)
        unsorted_fin = MASTFile("unsorted/parent_structure_labelfin")
        unsorted_fin.to_file("%s/parent_structure_labelfin" % ingdir)
        my_structure=pymatgen.io.vaspio.Poscar.from_file("files/perfect_structure").structure
        mywi = ChopIngredient(name=ingdir,program_keys=kdict,structure=my_structure)
        [sinit, sfin] = mywi.get_parent_structures()
        init_compare = pymatgen.io.vaspio.Poscar.from_file("files/parent_structure_labelinit").structure
        fin_compare = pymatgen.io.vaspio.Poscar.from_file("files/parent_structure_labelfin").structure
        #print sinit
        #print init_compare
        #print sfin
        #print fin_compare
        self.assertEqual(sinit.sites, init_compare.sites)
        self.assertEqual(sinit.lattice, init_compare.lattice)
        self.assertEqual(sfin.sites, fin_compare.sites)
        self.assertEqual(sfin.lattice, fin_compare.lattice)
        #self.testclass.get_parent_structures()
github uw-cmg / MAST / test / chop_test_complete / test_completeingredient.py View on Github external
def test_complete_subfolders(self):
        #raise SkipTest
        ingdir="%s/writedir/single_label1" % testdir
        recipedir="%s/writedir" % testdir
        topmetad = MASTFile("files/top_metadata_single")
        topmetad.data.append("origin_dir = %s/files\n" % testdir) #give origin directory
        topmetad.to_file("writedir/metadata.txt")
        metad = MASTFile("files/metadata_single")
        metad.to_file("%s/metadata.txt" % ingdir)
        kdict=dict()
        kdict['mast_program'] = 'vasp'
        kdict['mast_kpoints'] = [2,2,2,"M"]
        kdict['mast_xc'] = 'pw91'
        my_structure = pymatgen.io.vaspio.Poscar.from_file("files/perfect_structure").structure
        mywr = ChopIngredient(name=ingdir, program_keys = kdict, structure=my_structure)
        myoutcar = MASTFile("files/OUTCAR_completed")
        myoszicar = MASTFile("files/OSZICAR_completed")
        for subdir in ['00','01','02','03','04']:
            subname = "%s/%s" % (ingdir, subdir)
            os.mkdir(subname)
            mywr.keywords['name'] = subname
            mywr.checker.keywords['name'] = subname
            mywr.write_singlerun()
            mywr.write_submit_script()
            myoutcar.to_file("%s/OUTCAR" % subname)
            myoszicar.to_file("%s/OSZICAR" % subname)
        myci = ChopIngredient(name=ingdir,program_keys=kdict, structure=my_structure)
        self.assertTrue(myci.complete_subfolders())
        os.remove("%s/04/OUTCAR" % ingdir)
        self.assertFalse(myci.complete_subfolders())
github uw-cmg / MAST / test / checker_test_vasp / test_vaspchecker.py View on Github external
def test_vasp_poscar_setup_has_poscar(self):
        compare_pos = pymatgen.io.vaspio.Poscar.from_file(os.path.join(testdir, "structure","POSCAR_perfect"))
        compare_pos.write_file(os.path.join(testdir,"childdir","POSCAR"))
        myvc = VaspChecker(name="childdir")
        mypos = myvc._vasp_poscar_setup()
        self.assertEqual(mypos.structure, compare_pos.structure)
github uw-cmg / MAST / test / phonon_test / test_ph.py View on Github external
import pymatgen
import numpy as np
from MAST.ingredients.pmgextend.vasp_extensions import *
from MAST.ingredients.frozenphonons import *
mypos = pymatgen.io.vaspio.Poscar.from_file("//home/tam/bin/git/MAST4pymatgen/test/nebtest/ep1/CONTCAR")
mypos.write_file("//home/tam/bin/git/MAST4pymatgen/test/nebtest/POSCAR_no_frozen")
mypos2 = make_one_unfrozen_atom_poscar(mypos, 3)
mypos.write_file("//home/tam/bin/git/MAST4pymatgen/test/nebtest/POSCAR_no_frozen_maybe")
mypos2.write_file("//home/tam/bin/git/MAST4pymatgen/test/nebtest/POSCAR_frozen_3")

myph = FrozenPhonons(parent_path="//home/tam/bin/git/MAST4pymatgen/test/nebtest/ep1",dir_name="//home/tam/bin/git/MAST4pymatgen/test/phtest/frozen",program="vasp")
myph.generate_files()
github uw-cmg / MAST / test / chop_test_write / test_writeingredient.py View on Github external
kdict['mast_kpoints']=[3,3,3,"G"]
        kdict['mast_xc']='pbe'
        kdict['mast_program']='vasp_neb'
        kdict['mast_coordinates']=list()
        kdict['mast_coordinates'].append('%s/files/POSCAR_coords_01' % testdir)
        kdict['mast_coordinates'].append('%s/files/POSCAR_coords_02' % testdir)
        kdict['mast_coordinates'].append('%s/files/POSCAR_coords_03' % testdir)
        neblines = list()
        neblines.append(["Cr","0.0 0.9 0.8","0.0 0.8 0.7"])
        neblines.append(["Cr","0.4 0.2 0.1","0.3 0.3 0.2"])
        neblines.append(["Cr","0.29 0.05 0.05","0.01 0.01 0.98"])
        neblines.append(["Ni","0.61 0.99 0.98","0.25 0.01 0.97"])
        kdict['mast_neb_settings']=dict()
        kdict['mast_neb_settings']['images']=3
        kdict['mast_neb_settings']['lines']=neblines
        my_structure=pymatgen.io.vaspio.Poscar.from_file("files/perfect_structure").structure
        mywi = ChopIngredient(name=ingdir,program_keys=kdict,structure=my_structure)
        mywi.write_neb()
        self.assertTrue(mywi.checker.is_ready_to_run())
        pos_compare_00 = MASTFile("files/POSCAR_grafted_00")
        pos_compare_01 = MASTFile("files/POSCAR_grafted_01")
        pos_compare_02 = MASTFile("files/POSCAR_grafted_02")
        pos_compare_03 = MASTFile("files/POSCAR_grafted_03")
        pos_compare_04 = MASTFile("files/POSCAR_grafted_04")
        mypos00 = MASTFile("writedir/neb_labelinit-labelfin/00/POSCAR")
        mypos01 = MASTFile("writedir/neb_labelinit-labelfin/01/POSCAR")
        mypos02 = MASTFile("writedir/neb_labelinit-labelfin/02/POSCAR")
        mypos03 = MASTFile("writedir/neb_labelinit-labelfin/03/POSCAR")
        mypos04 = MASTFile("writedir/neb_labelinit-labelfin/04/POSCAR")
        self.assertEqual(pos_compare_00.data, mypos00.data)
        self.assertEqual(pos_compare_01.data, mypos01.data)
        self.assertEqual(pos_compare_02.data, mypos02.data)
github uw-cmg / MAST / MAST / utility / diffusion_coefficient / diffusioncoefficient.py View on Github external
"""
        label=""
        if self.freqmodel == 1:
            if not 'w0' in self.freqdict.keys():
                raise MASTError(self.__class__.__name__, "Need a label for frequency w0 for one-frequency model.")
            label = self.freqdict['w0']
        else:
            if not 'w2' in self.freqdict.keys():
                raise MASTError(self.__class__.__name__, "Not enough frequencies to determine solute and host.")
            label = self.freqdict['w2']       
        [startlabel, tstlabel]=self.find_start_and_tst_labels(label)
        mydir = self.get_labeled_dir(startlabel, "stat","","neb")
        pospath = os.path.join(mydir, "POSCAR")
        if not os.path.isfile(pospath):
            raise MASTError(self.__class__.__name__, "No POSCAR in %s." % pospath)
        mypos = pymatgen.io.vaspio.Poscar.from_file(pospath)
        sitesym = mypos.site_symbols
        natoms = mypos.natoms
        hostidx=natoms.index(max(natoms))
        self.host=sitesym[hostidx]
        if len(natoms) > 1:
            solidx=natoms.index(min(natoms))
            self.solute=sitesym[solidx]
        if self.verbose == 1:
            print "host: ", self.host
            print "solute: ", self.solute
        return 
github uw-cmg / MAST / scripts / matgenie.py View on Github external
def convert_fmt(args):
    iformat = args.input_format[0]
    oformat = args.output_format[0]
    filename = args.input_filename[0]
    out_filename = args.output_filename[0]

    try:
        if iformat == "smart":
            structure = read_structure(filename)
        if iformat == "POSCAR":
            p = Poscar.from_file(filename)
            structure = p.structure
        elif iformat == "CIF":
            r = CifParser(filename)
            structure = r.get_structures()[0]
        elif iformat == "CSSR":
            structure = Cssr.from_file(filename).structure

        if oformat == "smart":
            write_structure(structure, out_filename)
        elif oformat == "POSCAR":
            p = Poscar(structure)
            p.write_file(out_filename)
        elif oformat == "CIF":
            w = CifWriter(structure)
            w.write_file(out_filename)
        elif oformat == "CSSR":
github materialsproject / pymatgen / scripts / det_spacegroup.py View on Github external
help='Tolerance for symmetry determination')

args = parser.parse_args()
tolerance = float(args.tolerance[0]) if args.tolerance else 0.1

file_format = args.format

if args.input_file[0].lower().endswith(".cif"):
    file_format = "cif"
elif args.input_file[0].upper().startswith("POSCAR"):
    file_format = "poscar"

s = None

if file_format == 'poscar':
    p = Poscar.from_file(args.input_file[0])
    s = p.struct
else:
    r = CifParser(args.input_file[0])
    s = r.get_structures(False)[0]

if s:
    finder = SymmetryFinder(s, tolerance)
    dataset = finder.get_symmetry_dataset()
    print "Spacegroup  : {}".format(dataset['international'])
    print "Int number  : {}".format(dataset['number'])
    print "Hall symbol : {}".format(dataset["hall"])
github uw-cmg / MAST / MAST / utility / diffusion_coefficient / diffusioncoefficient.py View on Github external
append : append for name 
                perf : perfect-cell designation
            Return:
                : defect formation energy
        """
        [startlabel, tstlabel]=self.find_start_and_tst_labels(label)
        defpath=self.get_labeled_dir(startlabel, append, "", "neb")
        perfpath=self.get_labeled_dir(perf, append)
        defectedenergy = self.get_total_energy(defpath)
        perfectenergy = self.get_total_energy(perfpath)
        if defectedenergy==None or perfectenergy==None:
            raise MASTError(self.__class__.__name__,"No defected energy found.")
        delta = defectedenergy - perfectenergy
        refpure=0 # Need to get this from a calc??
        if refpure==0:
            mypos=pymatgen.io.vaspio.Poscar.from_file(os.path.join(perfpath, "POSCAR"))
            totatoms=sum(mypos.natoms)
            refpure=perfectenergy/totatoms
            #myfile=MASTFile()
            #myfile.data.append("WARNING: Cohesive energy has not been properly calculated in %s because a pseudopotential reference has not been taken into account." % perfpath)
            #myfile.to_file(os.path.join(self.directory,"WARNING"))
        eform = delta + refpure #Add on reference atom
        if self.verbose == 1:
            print "Eform: ", eform
        return eform