def read_con(filename): f = open(filename, 'r') lines = f.readlines() f.close() trajectory = [] line_index = 0 while True: try: boxlengths = numpy.array([ float(length) for length in lines[line_index + 2].split()[0:3] ]) boxangles = numpy.array( [float(angle) for angle in lines[line_index + 3].split()[0:3]]) cell = length_angle_to_box(boxlengths, boxangles) num_types = int(lines[line_index + 6].split()[0]) num_each_type = [ int(n) for n in lines[line_index + 7].split()[0:num_types] ] mass_each_type = [ float(n) for n in lines[line_index + 8].split()[0:num_types] ] a = Atoms('H' * sum(num_each_type)) a.cell = cell a.set_pbc((True, True, True)) frozen = [] positions = [] symbols = [] masses = [] line_index += 9 atom_index = 0 for i in range(num_types): symbol = lines[line_index].strip() mass = mass_each_type[i] line_index += 2 for j in range(num_each_type[i]): split = lines[line_index].split() positions.append([float(s) for s in split[0:3]]) symbols.append(symbol) masses.append(mass) if split[3] != '0': frozen.append(atom_index) atom_index += 1 line_index += 1 a.set_chemical_symbols(symbols) a.set_positions(positions) a.set_masses(masses) a.set_constraint(FixAtoms(frozen)) except: if len(trajectory) == 1: return trajectory[0] if len(trajectory) == 0: raise IOError, "Could not read con file." return trajectory trajectory.append(a)
def read_con(filename): f = open(filename, 'r') lines = f.readlines() f.close() trajectory = [] line_index = 0 while True: try: boxlengths = numpy.array([float(length) for length in lines[line_index+2].split()[0:3]]) boxangles = numpy.array([float(angle) for angle in lines[line_index+3].split()[0:3]]) cell = length_angle_to_box(boxlengths, boxangles) num_types = int(lines[line_index+6].split()[0]) num_each_type = [int(n) for n in lines[line_index+7].split()[0:num_types]] mass_each_type = [float(n) for n in lines[line_index+8].split()[0:num_types]] a = Atoms('H'*sum(num_each_type)) a.cell = cell a.set_pbc((True, True, True)) frozen = [] positions = [] symbols = [] masses = [] line_index += 9 atom_index = 0 for i in range(num_types): symbol = lines[line_index].strip() mass = mass_each_type[i] line_index += 2 for j in range(num_each_type[i]): split = lines[line_index].split() positions.append([float(s) for s in split[0:3]]) symbols.append(symbol) masses.append(mass) if split[3] != '0': frozen.append(atom_index) atom_index += 1 line_index += 1 a.set_chemical_symbols(symbols) a.set_positions(positions) a.set_masses(masses) a.set_constraint(FixAtoms(frozen)) except: if len(trajectory) == 1: return trajectory[0] if len(trajectory) == 0: raise IOError, "Could not read con file." return trajectory trajectory.append(a)
def load_feff_dat(filename): xk = [] cdelta = [] afeff = [] phfeff = [] redfac = [] xlam = [] rep = [] atoms = Atoms() atoms.set_pbc((False,False,False)) path_section = False atoms_section = False data_section = False f = open(filename) for line in f: line = line.strip() fields = line.split() if "genfmt" in line: path_section = True continue if fields[0] == "x" and fields[1] == "y" and fields[2] == "z": atoms_section = True path_section = False continue if fields[0] == "k" and fields[1] == "real[2*phc]": data_section = True atoms_section = False continue if path_section: if "---------------" in line: continue reff = float(fields[2]) path_section = False if atoms_section: x = float(fields[0]) y = float(fields[1]) z = float(fields[2]) pot = int(fields[3]) atomic_number = int(fields[4]) atoms.append(Atom(symbol=atomic_number, position=(x,y,z), tag=pot)) if data_section: fields = [ float(f) for f in fields ] xk.append(fields[0]) cdelta.append(fields[1]) afeff.append(fields[2]) phfeff.append(fields[3]) redfac.append(fields[4]) xlam.append(fields[5]) rep.append(fields[6]) xk = numpy.array(xk) cdelta = numpy.array(cdelta) afeff = numpy.array(afeff) phfeff = numpy.array(phfeff) redfac = numpy.array(redfac) xlam = numpy.array(xlam) rep = numpy.array(rep) return { "atoms":atoms, "reff":reff, "xk":xk, "cdelta":cdelta, "afeff":afeff, "phfeff":phfeff, "redfac":redfac, "xlam":xlam, "rep":rep, }