Пример #1
0
    def write_structure(self, filename):
        """See `pymatgen.io.smartio.write_structure`"""
        if filename.endswith(".nc"):
            raise NotImplementedError("Cannot write a structure to a netcdfile file yet")

        else:
            from pymatgen.io.smartio import write_structure
            write_structure(self, filename)
Пример #2
0
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":
            c = Cssr(structure)
            c.write_file(out_filename)
        elif oformat == "VASP":
            input_set = MPVaspInputSet()
            ts = TransformedStructure(structure, [],
                                      history=[{
                                          "source":
                                          "file",
                                          "datetime":
                                          str(datetime.datetime.now()),
                                          "original_file":
                                          open(filename).read()
                                      }])
            ts.write_vasp_input(input_set, output_dir=out_filename)
        elif oformat == "MITVASP":
            input_set = MITVaspInputSet()
            ts = TransformedStructure(structure, [],
                                      history=[{
                                          "source":
                                          "file",
                                          "datetime":
                                          str(datetime.datetime.now()),
                                          "original_file":
                                          open(filename).read()
                                      }])
            ts.write_vasp_input(input_set, output_dir=out_filename)

    except Exception as ex:
        print "Error converting file. Are they in the right format?"
        print str(ex)
Пример #3
0
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":
            c = Cssr(structure)
            c.write_file(out_filename)
        elif oformat == "VASP":
            input_set = MPVaspInputSet()
            ts = TransformedStructure(
                structure,
                [],
                history=[
                    {"source": "file", "datetime": str(datetime.datetime.now()), "original_file": open(filename).read()}
                ],
            )
            ts.write_vasp_input(input_set, output_dir=out_filename)
        elif oformat == "MITVASP":
            input_set = MITVaspInputSet()
            ts = TransformedStructure(
                structure,
                [],
                history=[
                    {"source": "file", "datetime": str(datetime.datetime.now()), "original_file": open(filename).read()}
                ],
            )
            ts.write_vasp_input(input_set, output_dir=out_filename)

    except Exception as ex:
        print "Error converting file. Are they in the right format?"
        print str(ex)
Пример #4
0
    def test_read_structure(self):
        test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..",
                                'test_files')
        for fname in ("Li2O.cif", "vasprun.xml",
                      "vasprun_Si_bands.xml", "Si.cssr"):
            filename = os.path.join(test_dir, fname)
            struct = read_structure(filename)
            self.assertIsInstance(struct, Structure)
            prim = read_structure(filename, primitive=True)
            self.assertLessEqual(len(prim), len(struct))
            sorted_s = read_structure(filename, sort=True)
            self.assertEqual(sorted_s, sorted_s.get_sorted_structure())

        m = StructureMatcher()
        for ext in [".cif", ".json", ".cssr"]:
            fn = "smartio_structure_test" + ext
            write_structure(struct, fn)
            back = read_structure(fn)
            self.assertTrue(m.fit(back, struct))
            os.remove(fn)
Пример #5
0
    def test_read_structure(self):
        test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..",
                                'test_files')
        for fname in ("Li2O.cif", "vasprun.xml", "vasprun_Si_bands.xml",
                      "Si.cssr"):
            filename = os.path.join(test_dir, fname)
            struct = read_structure(filename)
            self.assertIsInstance(struct, Structure)
            prim = read_structure(filename, primitive=True)
            self.assertLessEqual(len(prim), len(struct))
            sorted_s = read_structure(filename, sort=True)
            self.assertEqual(sorted_s, sorted_s.get_sorted_structure())

        m = StructureMatcher()
        for ext in [".cif", ".json", ".cssr"]:
            fn = "smartio_structure_test" + ext
            write_structure(struct, fn)
            back = read_structure(fn)
            self.assertTrue(m.fit(back, struct))
            os.remove(fn)
Пример #6
0
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":
            c = Cssr(structure)
            c.write_file(out_filename)
        elif oformat == "VASP":
            input_set = MaterialsProjectVaspInputSet()
            transmuter = StandardTransmuter.from_structures([structure], [])
            transmuter.write_vasp_input(input_set, output_dir=out_filename)

    except Exception as ex:
        print "Error converting file. Are they in the right format?"
        print str(ex)
Пример #7
0
Файл: fss.py Проект: uw-cmg/MAST
def finite_size_scale(standard, ssize, primordial, fsize, psize=[1,1,1]):
    """Function to perform finite size scaling for defect structure relaxation
    Inputs:
        standard = POSCAR file of structure containing defect
        ssize = Supercell size of structure with defect (list of size 3)
        primordial = POSCAR file of structure for basic unit of perfect cell
        psize = Supercell size of structure for padding. Default = [1,1,1] (list of size 3)
        fsize = Desired supercell size of final structure (list of size 3)
    Outputs:
        POSCAR file of structure containing defect and padding"""
    
    # Check if the input sizes work out with the desired final size
    padding = [0,0,0]
    for i in range(3):
        diff = fsize[i] - ssize[i]
        if diff < 0:
            raise RuntimeError('Desired final size of the structure must be larger than \
existing defect structure size. Defect Size = '+repr(ssize)+' Final Size = '+repr(fsize))
        elif diff >= 0:
             if math.fmod(diff,psize[i]):
                raise RuntimeError('Primordial structure and defect structure sizes cannot \
be used to form desired final size.  Reduce size of primordial structure. Defect Size = '+
    repr(ssize)+' Final Size = '+repr(fsize)+' Primordial size = '+repr(psize))
             else:
                padding[i] = diff/psize[i]
    
    # Load the defect structure and primordial structure
    try:
        defst = read_structure(standard)
    except:
        raise RuntimeError('Error: Unable to read standard structure.  Please check file. Filename: '+\
            standard)
    try:
        pst = read_structure(primordial)
    except:
        raise RuntimeError('Error: Unable to read primordial structure.  Please check file. Filename: '+\
            primordial)
    
    # Pad the structure
    positions = [site.coords for site in pst]
    syms = [str(site.specie.symbol) for site in pst]
    lv = [one/ssize for one in defst.lattice.matrix]
    vect = []
    for m0 in range(padding[0]):
        for m1 in numpy.arange(0,fsize[1],psize[1]):
            for m2 in numpy.arange(0,fsize[2],psize[2]):
                vect.append([ssize[0]+m0*psize[0],m1,m2])
    
    for m1 in range(padding[1]):
        for m0 in numpy.arange(0,ssize[0],psize[0]):
            for m2 in numpy.arange(0,fsize[2],psize[2]):
                vect.append([m0,ssize[1]+m1*psize[1],m2])
    
    for m2 in range(padding[2]):
        for m0 in numpy.arange(0,ssize[0],psize[0]):
            for m1 in numpy.arange(0,ssize[1],psize[1]):
                vect.append([m0,m1,ssize[2]+m2*psize[2]])
    
    #Construct a new structure with desired size
    new_lat = Lattice(numpy.array([fsize[c] * lv[c] for c in range(3)]))
    final = Structure(new_lat, defst.species_and_occu,defst.cart_coords,
            coords_are_cartesian=True)
    for m0,m1,m2 in vect:
        npos = positions + numpy.dot((m0, m1, m2), lv)
        for i in range(len(npos)):
            final.append(syms[i],npos[i],coords_are_cartesian=True)
    
    #Check for periodic issues in final structure
    final = check_periodic(final,defst)
    
    # Write output as POSCAR
    write_structure(final, 'POSCAR_Final')
    
    return final
Пример #8
0
Файл: fss.py Проект: uw-cmg/MAST
#		-definition of relative term can be ambiguous depending on structure
#	--Assumes defect structure and primordial structures are aligned

if __name__ == "__main__":
    #Sanity checks	
    #Test 1 - Final size cannot be constructed directly from primordial structure
    ssize=[5,5,5]
    fsize=[9,5,5]
    psize=[2,5,5]
    felat = Lattice.cubic(2.87)
    primf = Structure(felat,["Fe","Fe"],[[0,0,0],[0.5,0.5,0.5]])
    primordialstructure = primf.copy()
    primordialstructure.make_supercell(psize)
    f = primf.copy()
    f.make_supercell(fsize)
    write_structure(primordialstructure,'POSCAR_prim1')
    final = finite_size_scale('POSCAR_Fdefect', ssize, 'POSCAR_prim1', fsize, psize)
    write_structure(f,'POSCAR_F1expected')
    write_structure(final,'POSCAR_F1')
    
    #Test 2 - Test in all 3 dimensions
    ssize=[5,5,5]
    fsize=[8,8,8]
    psize=[1,1,1]
    primordialstructure = primf.copy()
    primordialstructure.make_supercell(psize)
    f = primf.copy()
    f.make_supercell(fsize)
    write_structure(primordialstructure, 'POSCAR_prim2')
    final = finite_size_scale('POSCAR_Fdefect', ssize, 'POSCAR_prim2', fsize, psize)
    write_structure(f,'POSCAR_F2expected')
Пример #9
0
def finite_size_scale(standard, ssize, primordial, fsize, psize=[1, 1, 1]):
    """Function to perform finite size scaling for defect structure relaxation
    Inputs:
        standard = POSCAR file of structure containing defect
        ssize = Supercell size of structure with defect (list of size 3)
        primordial = POSCAR file of structure for basic unit of perfect cell
        psize = Supercell size of structure for padding. Default = [1,1,1] (list of size 3)
        fsize = Desired supercell size of final structure (list of size 3)
    Outputs:
        POSCAR file of structure containing defect and padding"""

    # Check if the input sizes work out with the desired final size
    padding = [0, 0, 0]
    for i in range(3):
        diff = fsize[i] - ssize[i]
        if diff < 0:
            raise RuntimeError(
                'Desired final size of the structure must be larger than \
existing defect structure size. Defect Size = ' + repr(ssize) +
                ' Final Size = ' + repr(fsize))
        elif diff >= 0:
            if math.fmod(diff, psize[i]):
                raise RuntimeError(
                    'Primordial structure and defect structure sizes cannot \
be used to form desired final size.  Reduce size of primordial structure. Defect Size = '
                    + repr(ssize) + ' Final Size = ' + repr(fsize) +
                    ' Primordial size = ' + repr(psize))
            else:
                padding[i] = diff / psize[i]

    # Load the defect structure and primordial structure
    try:
        defst = read_structure(standard)
    except:
        raise RuntimeError('Error: Unable to read standard structure.  Please check file. Filename: '+\
            standard)
    try:
        pst = read_structure(primordial)
    except:
        raise RuntimeError('Error: Unable to read primordial structure.  Please check file. Filename: '+\
            primordial)

    # Pad the structure
    positions = [site.coords for site in pst]
    syms = [str(site.specie.symbol) for site in pst]
    lv = [one / ssize for one in defst.lattice.matrix]
    vect = []
    for m0 in range(padding[0]):
        for m1 in numpy.arange(0, fsize[1], psize[1]):
            for m2 in numpy.arange(0, fsize[2], psize[2]):
                vect.append([ssize[0] + m0 * psize[0], m1, m2])

    for m1 in range(padding[1]):
        for m0 in numpy.arange(0, ssize[0], psize[0]):
            for m2 in numpy.arange(0, fsize[2], psize[2]):
                vect.append([m0, ssize[1] + m1 * psize[1], m2])

    for m2 in range(padding[2]):
        for m0 in numpy.arange(0, ssize[0], psize[0]):
            for m1 in numpy.arange(0, ssize[1], psize[1]):
                vect.append([m0, m1, ssize[2] + m2 * psize[2]])

    #Construct a new structure with desired size
    new_lat = Lattice(numpy.array([fsize[c] * lv[c] for c in range(3)]))
    final = Structure(new_lat,
                      defst.species_and_occu,
                      defst.cart_coords,
                      coords_are_cartesian=True)
    for m0, m1, m2 in vect:
        npos = positions + numpy.dot((m0, m1, m2), lv)
        for i in range(len(npos)):
            final.append(syms[i], npos[i], coords_are_cartesian=True)

    #Check for periodic issues in final structure
    final = check_periodic(final, defst)

    # Write output as POSCAR
    write_structure(final, 'POSCAR_Final')

    return final
Пример #10
0
#		-definition of relative term can be ambiguous depending on structure
#	--Assumes defect structure and primordial structures are aligned

if __name__ == "__main__":
    #Sanity checks
    #Test 1 - Final size cannot be constructed directly from primordial structure
    ssize = [5, 5, 5]
    fsize = [9, 5, 5]
    psize = [2, 5, 5]
    felat = Lattice.cubic(2.87)
    primf = Structure(felat, ["Fe", "Fe"], [[0, 0, 0], [0.5, 0.5, 0.5]])
    primordialstructure = primf.copy()
    primordialstructure.make_supercell(psize)
    f = primf.copy()
    f.make_supercell(fsize)
    write_structure(primordialstructure, 'POSCAR_prim1')
    final = finite_size_scale('POSCAR_Fdefect', ssize, 'POSCAR_prim1', fsize,
                              psize)
    write_structure(f, 'POSCAR_F1expected')
    write_structure(final, 'POSCAR_F1')

    #Test 2 - Test in all 3 dimensions
    ssize = [5, 5, 5]
    fsize = [8, 8, 8]
    psize = [1, 1, 1]
    primordialstructure = primf.copy()
    primordialstructure.make_supercell(psize)
    f = primf.copy()
    f.make_supercell(fsize)
    write_structure(primordialstructure, 'POSCAR_prim2')
    final = finite_size_scale('POSCAR_Fdefect', ssize, 'POSCAR_prim2', fsize,