Пример #1
0
    def strout2poscar(src='str.out'):
        """
        str.outをposcarの記述に変換し, Poscar objをreturn
        """
        with open(src, 'r') as rfile:
            lines = rfile.readlines()
        latt_tmp = [[float(x) for x in y.split()] for y in lines[0:3]]
        trans = [[float(x) for x in y.split()] for y in lines[3:6]]
        sites_tmp = [[float(x) for x in y.split()[0:3]] for y in lines[6:]]
        elements = [x.split()[3].split('+')[0].split('-')[0] for x in lines[6:]]
        num_atoms = [elements.count(e)
                     for e in sorted(set(elements), key=elements.index)]
        latt = np.dot(np.array(trans), np.array(latt_tmp))
        sites = np.dot(np.array(sites_tmp), np.array(latt_tmp))

        posc_str = "posc_orig\n"
        posc_str += "1.00\n"
        posc_str += "\n".join(["  ".join([str(f) for f in l]) for l in latt])
        posc_str += "\n"
        posc_str += "  ".join(sorted(set(elements), key=elements.index)) + "\n"
        posc_str += "  ".join([str(d) for d in num_atoms]) + "\n"
        posc_str += "Cartesian\n"
        posc_str += "\n".join(["  ".join([str(f) for f in s]) for s in sites])

        return Poscar.from_string(posc_str)
Пример #2
0
    def test_init(self):
        filepath = os.path.join(test_dir, 'POSCAR')
        poscar = Poscar.from_file(filepath)
        comp = poscar.struct.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.struct.composition, Composition.from_formula("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.struct.composition, Composition.from_formula("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]])
Пример #3
0
    def from_poscar_string(poscar_string, transformations=[]):
        """
        Generates TransformedStructure from a poscar string. 

        Args:
            poscar_string:
                Input POSCAR string.
        """
        p = Poscar.from_string(poscar_string)
        if not p.true_names:
            raise ValueError("Transformation can be craeted only from POSCAR strings with proper VASP5 element symbols.")
        raw_string = re.sub("'", "\"", poscar_string)
        s = p.struct
        source_info = {'source': "uploaded POSCAR", 'datetime':str(datetime.datetime.now()), 'original_file':raw_string}
        return TransformedStructure(s, transformations, [source_info])
Пример #4
0
def get_minkowski_red(structure):
    """
    get a minkowski reduced structure
    """
    from pymatgen.io.vaspio import Poscar
    output = run_aconvasp_command(['aconvasp', '--kpath'], structure)
    started = False
    poscar_string = ""
    for line in output[0].split("\n"):
        if started or line.find("KPOINTS TO RUN") != -1:
            poscar_string = poscar_string + line + "\n"
        if line.find("STRUCTURE TO RUN") != -1:
            started = True
        if line.find("KPOINTS TO RUN") != -1:
            started = False
    return Poscar.from_string(poscar_string).struct