Beispiel #1
0
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)
Beispiel #2
0
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)