예제 #1
0
def bonds_from_ff(atoms, linkers, ff):
    ff_bonds = []
    found = False
    for line in read_file(ff):
        if "BONDS" in line:
            found = True
        if "ANGLES" in line:
            break
        if found and not re.search("^\s*$", line):
            line = line.split()
            if all(x in atoms for x in line[:2]):
                ff_bonds.append(line[:2] + line[3:5])
    # add on linkers by copying lines that include the type after forming
    # the bond
    additional = []
    for linker, newtype in linkers.items():
        for bond in ff_bonds:
            if newtype in bond[:2]:
                tmp = bond.copy()
                for ind, i in enumerate(tmp):
                    if i == newtype:
                        tmp[ind] = linker
                        additional.append(tmp)
                        break
                        # only want to replace one instance of C3, so we have C3, LC1
    ff_bonds += additional
    ret = []
    for i in ff_bonds:
        if i not in ret:
            ret.append(i)
    return ret
예제 #2
0
def params_from_initial_datafile(datafile):
    params = {}
    params["atoms"] = []
    params["pairs"] = []
    params["bonds"] = []
    params["angles"] = []
    params["dihs"] = []
    params["imps"] = []

    atoms = False
    pairs = False
    bonds = False
    angles = False
    dihs = False
    imps = False
    for line in read_file(datafile):
        if "Masses" in line:
            atoms = True
            continue
        if "Pair Coeffs" in line:
            atoms = False
            pairs = True
            continue
        if "Bond Coeffs" in line:
            pairs = False
            bonds = True
            continue
        if "Angle Coeffs" in line:
            bonds = False
            angles = True
            continue
        if "Dihedral Coeffs" in line:
            angles = False
            dihs = True
            continue
        # improps not always present
        if re.search("^\s*[A-Z]", line):
            dihs = False
        if "Improper Coeffs" in line:
            imps = True
            continue
        if "Atoms" in line:
            break
        if re.search("^\s*$", line):
            continue
        line = line.split()
        if atoms and re.search("^\s*[0-9]", line[0]):
            params["atoms"].append(line[-1])
        if pairs and re.search("^\s*[0-9]", line[0]):
            params["pairs"].append(line[-1])
        if bonds and re.search("^\s*[0-9]", line[0]):
            params["bonds"].append(line[-1])
        if angles and re.search("^\s*[0-9]", line[0]):
            params["angles"].append(line[-1])
        if dihs and re.search("^\s*[0-9]", line[0]):
            params["dihs"].append(line[-1])
        if imps and re.search("^\s*[0-9]", line[0]):
            params["imps"].append(line[-1])

    return params
예제 #3
0
def change_datafile(charges, datafile, output):
    b4_atoms = []
    atoms = []
    after_atoms = []
    b4_atoms_bool = True
    found_atoms_bool = False
    after_atoms_bool = False
    for line in read_file(datafile):
        if re.search('\s*Atoms', line):
            b4_atoms_bool = False
            found_atoms_bool = True
        if re.search('^\s*Bonds', line):
            found_atoms_bool = False
            after_atoms_bool = True
        if b4_atoms_bool:
            b4_atoms.append(line)
        if found_atoms_bool:
            atoms.append(line)
        if after_atoms_bool:
            after_atoms.append(line)

    newatoms = []
    for line, charge in zip(atoms[2:-1], charges):
        line = line.split()
        line[3] = str(charge)  # change column
        newatoms.append(' '.join(line) + '\n')
    atoms = atoms[:2] + newatoms + [atoms[-1]]

    with open(output, 'w') as f:
        f.writelines(b4_atoms)
        f.writelines(atoms)
        f.writelines(after_atoms)
예제 #4
0
def main():
    file = 'gaff.lt'
    file = read_file(file)
    find_masses(file, atoms)
    pair_coeffs(file, atoms)
    bond_coeffs(file, bonds)
    angle_coeffs(file, angles)
    dihedral_coeffs(file, dihs)
    improper_coeffs(file, imps)
    write_file(atoms, bonds, angles, dihs, imps)
예제 #5
0
def linker_atom_types(datafile, polym="polym.in", ff="gaff.ff"):
    atoms_to_consider = []
    linkers = {}
    for line in read_file(polym):
        if "link" in line:
            tmp = line.split()[1:]
            for i in tmp:
                atoms_to_consider += i.split(",")
                linker, after_bond = i.split(",")
                linkers[linker] = after_bond
    atoms_to_consider = list(set(atoms_to_consider))

    atom_types = []
    # find atom types of each atom label,
    # then just add all possible parameters
    for line in read_file(ff):
        if "BONDS" in line:
            break
        line = line.split()
        if len(line) > 6:
            if line[0] in atoms_to_consider:
                atom_types.append(line[1])

    # Add atom types of atoms bonded to the linker atoms.
    # To do this, need to create the original monomer system,
    # and read in bond types
    found = False
    for line in read_file(datafile):
        if "Bond Coeffs" in line:
            found = True
            continue
        if "Atom Coeffs" in line:
            break
        line = line.split()
        if len(line) < 5:
            continue
        if any(x in line[-1] for x in atoms_to_consider):
            atom_types += line[-1].split("-")
    return list(set(atom_types)), linkers
예제 #6
0
def dihs_from_ff(atoms, linkers, ff, params_in_original_datafile):
    all_combos, with_types_that_exist = find_combos(
        atoms, linkers, params_in_original_datafile)

    ff_dihs = []
    found = False
    for line in read_file(ff):
        if "DIHEDRALS" in line:
            found = True
            continue
        if re.search("^\s*$", line) and len(ff_dihs) > 0:
            break
        if found and not re.search("^\s*$", line):
            ff_dihs.append(line.split())
    return compare_db(ff_dihs, all_combos, with_types_that_exist)
예제 #7
0
def atoms_from_ff(atoms, ff):
    ff_atoms = []
    ff_pairs = []
    found = False
    for line in read_file(ff):
        if "ATOMS" in line:
            found = True
            continue
        if "BONDS" in line:
            break
        if found and not re.search("^\s*$", line):
            line = line.split()
            if line[0] in atoms:
                ff_atoms.append([line[0], line[2]])
                ff_pairs.append([line[0]] + line[5:7])
    return ff_atoms, ff_pairs
예제 #8
0
def imps_from_ff(atoms, linkers, ff, params_in_original_datafile):
    """
    Same as dihs from ff, just changing the values in the force field 
    to search for
    """
    all_combos, with_types_that_exist = find_combos(
        atoms, linkers, params_in_original_datafile)

    ff_dihs = []

    found = False
    for line in read_file(ff):
        if "IMPROPERS" in line:
            found = True
            continue
        if found and not re.search("^\s*$", line):
            ff_dihs.append(line.split())

    return compare_db(ff_dihs, all_combos, with_types_that_exist)
예제 #9
0
mol_id = []
mol_count = 1
for s in structs:
    for _ in range(mols[s]['number']):
        for _ in range(mols[s]["length"]):
            mol_id.append(mol_count)
        mol_count += 1
# now change data file

b4_atoms = []
atoms = []
after_atoms = []
b4_atoms_bool = True
found_atoms_bool = False
after_atoms_bool = False
for line in read_file(lammps):
    if re.search('\s*Atoms', line):
        b4_atoms_bool = False
        found_atoms_bool = True
    if re.search('^\s*Bonds', line):
        found_atoms_bool = False
        after_atoms_bool = True
    if b4_atoms_bool:
        b4_atoms.append(line)
    if found_atoms_bool:
        atoms.append(line)
    if after_atoms_bool:
        after_atoms.append(line)

newatoms = []
for line, molid in zip(atoms[2:-1], mol_id):
예제 #10
0
charge_regex = '^\s[A-Za-z]{1,2}(\s*-?[0-9]*.[0-9]*){2}$'

results = []

files = get_files('.', ['log', 'out'])

for logfile in files:
    if file_is_gamess(logfile):
        path, filename = os.path.split(logfile)
        print(path)
        inpfile = logfile[:-3] + 'inp'

        res = []
        assigned = []

        for line in read_file(inpfile):
            if re.search(atom_regex, line):
                sym, atnum, x, y, z = line.split()
                x, y, z = map(float, (x, y, z))
                res.append([path,
                            Atom(sym,
                                 coords=(x, y, z))])  # new key for each coord
        found = False
        counter = 0
        for line in read_file(logfile):
            if 'NET CHARGES:' in line:
                found = True
            if 'RMS DEVIATION' in line:
                break
            if found:
                if re.search(charge_regex, line):
예제 #11
0
def angles_from_ff(atoms, linkers, ff, params_in_original_datafile):
    ff_angles = []
    found = False
    for line in read_file(ff):
        if "ANGLES" in line:
            found = True
        if "DIHEDRALS" in line:
            break
        if found and not re.search("^\s*$", line):
            line = line.split()
            if all(x in atoms for x in line[:3]):
                ff_angles.append(line[:3] + line[4:6])

    orig_atoms = []
    for ang in params_in_original_datafile:
        for atom in ang.split("-"):
            if atom not in orig_atoms:
                orig_atoms.append(atom)
    all_atoms = []
    for atom in atoms + orig_atoms:
        if atom not in all_atoms:
            all_atoms.append(atom)
    all_combos = list(list(i) for i in itertools.product(all_atoms, repeat=3))
    with_types_that_exist = []
    for combo in all_combos:
        with_types_that_exist.append(
            [linkers[i] if i in linkers else i for i in combo])

    # add on linkers by copying lines that include the type after forming
    # the angle
    angles_with_params = []
    for line in ff_angles:
        for combo, types_that_exist in zip(all_combos, with_types_that_exist):
            if line[:3] == types_that_exist:
                params = line[3:]
                angles_with_params.append(combo + params)
                angles_with_params.append(types_that_exist + params)
                possibility = []
                tmpval = combo
                # find each possible different combination,
                # i.e. for combo = [LC1, LC2, CA] and
                # types_that_exist = [C3, C3, CA],
                # also include LC1, C3, CA and
                #              C3, LC2, CA
                for idx, data in enumerate(zip(combo, types_that_exist)):
                    with_linker, without_linker = data
                    if with_linker != without_linker:
                        # change one value and add it
                        to_add = tmpval.copy()
                        to_add[idx] = without_linker
                        possibility.append(to_add)
                for p in possibility:
                    angles_with_params.append(p + params)

    # prevent duplicates...
    checked = []
    ret = []
    for angle in angles_with_params:
        if angle[:3] not in checked:
            checked.append(angle[:3])
            ret.append(angle)
    return ret

    ff_angles = initial + additional
    ret = []
    for i in ff_angles:
        if i not in ret:
            ret.append(i)
    return ret
예제 #12
0
cm5_results = []

files = get_files('.', ['.log', '.out'])
regex = "\s*[0-9]{1,3}\s*[A-Za-z]{1,2}(\s*\D?[0-9]{1,3}\.[0-9]{1,10}){6}"
inp_regex = '^[A-Z][a-z]?(\s*-?[0-9]*.[0-9]*){3}'

found = False
for file in files:
    path, f = os.path.split(file)
    print(path)
    inputfile = file.replace('out', 'inp')
    data = []
    coords = []
    parsed = []
    lines = read_file(file)
    for line in lines:
        if 'Q-H        S-H        Dx         Dy         Dz        Q-CM5' in line:
            found = True
        elif 'Tot' in line:
            found = False
        if found:
            # index, sym, hirshfeld charge, spin density, dipole_x, dipole_y, dipole_z, cm5 charge
            if re.search(regex, line):
                res = line.split()
                data.append([path] + res[:3] + res[4:])

    # need coords
    for line in read_file(inputfile):
        if re.search(inp_regex, line):
            sym, x, y, z = line.split()