Example #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)
Example #2
0
 def _parse_structure(self, structure_schema):
     data = structure_schema['data']
     format = structure_schema['format']
     if format == 'cif':
         structure = (CifParser.from_string(data)).get_structures()[0]
     elif format == 'POSCAR':
         structure = (Poscar.from_string(data)).structure
     return structure
Example #3
0
 def _parse_structure(self, structure_schema):
     data = structure_schema['data']
     format = structure_schema['format']
     if format == 'cif':
         # cif lattice can be weird non standard shape
         structure = (CifParser.from_string(data)).get_structures()[0]
         lattice = pmg.Lattice.from_parameters(*structure.lattice.abc, *structure.lattice.angles)
         structure = pmg.Structure(lattice, structure.species, structure.frac_coords, coords_are_cartesian=False)
     elif format == 'POSCAR':
         structure = (Poscar.from_string(data)).structure
     return structure
Example #4
0
def poscar_scale(poscar_in, poscar_out, scale):
    with open(poscar_in, 'r') as fin:
        lines = list(fin)
    if 'D' == lines[7][0] or 'd' == lines[7][0]:
        lines = poscar_scale_direct(lines, scale)
    elif 'C' == lines[7][0] or 'c' == lines[7][0]:
        lines = poscar_scale_cartesian(lines, scale)
    else:
        raise RuntimeError("Unknow poscar style at line 7: %s" % lines[7])

    poscar = Poscar.from_string("".join(lines))
    with open(poscar_out, 'w') as fout:
        fout.write(poscar.get_string(direct=False))
Example #5
0
 def _parse_structure(self, structure_schema):
     data = structure_schema['data']
     format = structure_schema['format']
     if format == 'cif':
         # cif lattice can be weird non standard shape
         structure = (CifParser.from_string(data)).get_structures()[0]
         lattice = pmg.Lattice.from_parameters(*structure.lattice.abc,
                                               *structure.lattice.angles)
         structure = pmg.Structure(lattice,
                                   structure.species,
                                   structure.frac_coords,
                                   coords_are_cartesian=False)
     elif format == 'POSCAR':
         structure = (Poscar.from_string(data)).structure
     return structure
Example #6
0
def get_structure(f):
    name = f.name
    content = f.read()
    content = content.decode("utf-8")
    if "POSCAR" in name or "CONTCAR" in name:
        s = Poscar.from_string(content, False).structure
    elif ".cif" in name.lower():
        parser = CifParser.from_string(content)
        s = parser.get_structures(False)[0]
    elif ".cssr" in name.lower():
        cssr = Cssr.from_string(content)
        s = cssr.structure
    elif ".mson" in name.lower():
        s = json.loads(content, cls=MontyDecoder)
        if type(s) != Structure:
            raise IOError("File does not contain a valid serialized "
                          "structure")
    else:
        raise ValueError(name + " is an invalid file format. Only "
                         "POSCAR, CIF, CSSR and MSON (Materials "
                         "Project JSON) are supported right now.")
    return name, s
Example #7
0
    return np.array([[xx, 0, 0], [yx, yy, 0], [zx, zy, zz]])


def lammps_friendly(structure):
    orig_lattice = structure.lattice.matrix
    lmp_lattice = lammps_lattice(orig_lattice)
    fracs = structure.frac_coords
    return Structure(lmp_lattice, structure.species, fracs)


input = sys.argv[1]

import lzma, json
with lzma.open(os.path.join(input, 'structure.vasp.xz'), 'rt') as f:
    structure = Poscar.from_string(f.read()).structure
with lzma.open(os.path.join(input, 'layers.json.xz'), 'rt') as f:
    layers = json.load(f)

num_types = max(layers) + 1

structure = lammps_friendly(structure)
carts = structure.cart_coords
lattice = structure.lattice.matrix
species = structure.species
print()
print()
print(f'{len(carts)} atoms')
print()
print(f'{num_types} atom types')
print()
Example #8
0
from featurebox.data.impot_element_table import element_table

name_and_abbr = element_table.iloc[[0, 1], :]
element_table = element_table.iloc[2:, :]
elemen = element_table[[
    'electronegativity(martynov&batsanov)', 'electron number'
]]

dict_all = []
for i in tqdm(list_name):
    try:
        a = json.read_json(i, orient='index', typ='series')
        cif_str = a["Structure_rlx"]
        del a["Structure_rlx"]

        POSCAR = Poscar.from_string(cif_str)
        ele_den = POSCAR.structure.composition.total_electrons / POSCAR.structure.volume
        composition_mp = POSCAR.structure.composition

        ncom = POSCAR.structure.composition.to_data_dict[
            'unit_cell_composition'].values()

        sym_amt = composition_mp.get_el_amt_dict()
        syms = sorted(sym_amt.keys(), key=lambda sym: get_el_sp(sym).X)
        formula = {s: formula_double_format(sym_amt[s], False) for s in syms}

        departElementProPFeature = DepartElementFeaturizer(
            elem_data=elemen,
            n_composition=len(ncom),
            n_jobs=1,
            return_type='df')
Example #9
0
def lammps_friendly(structure):
    orig_lattice = structure.lattice.matrix
    lmp_lattice = lammps_lattice(orig_lattice)
    fracs = structure.frac_coords
    return Structure(lmp_lattice, structure.species, fracs)

input = sys.argv[1]
if input.endswith('.xz'):
    import lzma
    with lzma.open(input, 'rt') as f:
        poscar_str = f.read()
else:
    with open(input, 'rt') as f:
        poscar_str = f.read()
structure = Poscar.from_string(poscar_str).structure
structure = lammps_friendly(structure)
carts = structure.cart_coords
lattice = structure.lattice.matrix
species = structure.species
print()
print()
print(f'{len(carts)} atoms')
print()
print(f'2 atom types')
print()
print(f'0.0 {lattice[0][0]} xlo xhi')
print(f'0.0 {lattice[1][1]} ylo yhi')
print(f'0.0 {lattice[2][2]} zlo zhi')
print(f'{lattice[1][0]} {lattice[2][0]} {lattice[2][1]} xy xz yz')
print()