def _read_cif_block(cb): s = strx.Structure() s.cell = latparams_to_basis(_get_lattice_parameters(cb)) sym_ops = _get_sym_ops(cb) ox_data = _get_oxidation_state_data(cb) for atom in cb.GetLoop('_atom_site_label'): na = _get_atom(atom) if ox_data: na.ox = ox_data.get(atom._atom_site_type_symbol, None) for rot, trans in zip(*sym_ops): coord = np.dot(rot, na.coord) + trans coord = wrap(coord) a = na.copy() a.coord = coord s.add_atom(a, tol=1e-1) s.composition = comp.Composition.get(s.comp) ## meta data s.r_val = float(cb.get('_refine_ls_R_factor_all', 0.0)) s.temperature = _get_value(cb.get('_cell_measurement_temperature', 0.0)) s.pressure = _get_value(cb.get('_cell_measurement_pressure', 0.0)) if cb.get('_chemical_name_structure_type'): s.prototype = strx.Prototype.get(cb.get('_chemical_name_structure_type')) try: s.reported_composition = strx.Composition.get( parse_comp(cb.get('_chemical_formula_sum'))) except: pass s.input_format = 'cif' s.natoms = len(s) s.get_volume() return s
def read(poscar, species=None): """ Read a POSCAR format file. Reads VASP 4.x and 5.x format POSCAR files. Keyword Arguments: `species`: If the file is 4.x format and the title line doesn't indicate what species are present, you must supply them (in the correct order) with the `species` keyword. Raises: POSCARError: If species data is not available. Examples:: >>> io.poscar.read(INSTALL_PATH+'/io/files/POSCAR_FCC') """ # Initialize the structure output struct = st.Structure() # Read in the title block, and system sell if isinstance(poscar, StringIO.StringIO): poscar = poscar else: poscar = open(poscar, 'r') title = poscar.readline().strip() scale = float(poscar.readline().strip()) s = float(scale) cell = [[float(v) for v in poscar.readline().split()], [float(v) for v in poscar.readline().split()], [float(v) for v in poscar.readline().split()]] cell = np.array(cell) if s > 0: struct.cell = cell * s else: struct.cell = cell struct.volume = -1 * s # Determine whether POSCAR is in VASP 5 format # VASP 5 has the elements listed after the # the cell parameters vasp5 = False _species = poscar.readline().strip().split() try: float(_species[0]) except: vasp5 = True counts = [int(v) for v in poscar.readline().split()] # If the format is not VASP 5, the elements should # have been listed in the title if not vasp5: counts = map(int, _species) if not species: _species = title.strip().split() for s in _species: if not s in qmpy.elements.keys(): msg = 'In VASP4.x format, title line MUST be species present' raise POSCARError else: _species = species species = _species # Prepare a list of numbers of atom types atom_types = [] for n, e in zip(counts, species): atom_types += [e] * n # Determine whether coordinates are in direct or cartesian direct = False style = poscar.readline() if style[0].lower() == 's': # The POSCAR contains selective dynamics info style = poscar.readline() if style[0] in ['D', 'd']: direct = True # Read in the atom coordinates struct.natoms = sum(counts) struct.ntypes = len(counts) atoms = [] inv = np.linalg.inv(cell).T for i in range(struct.natoms): atom = st.Atom() atom.element_id = atom_types[i] if direct: atom.coord = [float(v) for v in poscar.readline().split()[0:3]] else: cart = [float(v) for v in poscar.readline().split()[0:3]] atom.coord = np.dot(inv, cart) struct.add_atom(atom) struct.get_volume() struct.set_composition() return struct
def read(poscar, species=None): """ Read a POSCAR format file. Reads VASP 4.x and 5.x format POSCAR files. Keyword Arguments: `species`: If the file is 4.x format and the title line doesn't indicate what species are present, you must supply them (in the correct order) with the `species` keyword. Raises: POSCARError: If species data is not available. Examples:: >>> io.poscar.read(INSTALL_PATH+'/io/files/POSCAR_FCC') """ struct = st.Structure() poscar = open(poscar, 'r') title = poscar.readline().strip() scale = float(poscar.readline().strip()) s = float(scale) cell = [[float(v) for v in poscar.readline().split()], [float(v) for v in poscar.readline().split()], [float(v) for v in poscar.readline().split()]] cell = np.array(cell) if s > 0: struct.cell = cell * s else: struct.cell = cell struct.volume = -1 * s vasp5 = False _species = poscar.readline().strip().split() try: float(_species[0]) except: vasp5 = True counts = [int(v) for v in poscar.readline().split()] if not vasp5: counts = map(int, _species) if not species: _species = title.strip().split() for s in _species: if not s in qmpy.elements.keys(): msg = 'In VASP4.x format, title line MUST be species present' raise POSCARError else: _species = species species = _species atom_types = [] for n, e in zip(counts, species): atom_types += [e] * n style = poscar.readline() direct = False if style[0] in ['D', 'd']: direct = True struct.natoms = sum(counts) struct.ntypes = len(counts) atoms = [] inv = np.linalg.inv(cell).T for i in range(struct.natoms): atom = st.Atom() atom.element_id = atom_types[i] if direct: atom.coord = [float(v) for v in poscar.readline().split()[0:3]] else: cart = [float(v) for v in poscar.readline().split()[0:3]] atom.coord = np.dot(inv, cart) struct.add_atom(atom) struct.get_volume() struct.set_composition() return struct