Exemple #1
0
def writePRM(mol, parameters, filename):
    from htmd.version import version as htmdversion
    from htmd.util import ensurelist

    # for type, val in parameters.atom_types.items():
    #     if val.epsilon_14 != 1.0:
    #         raise ValueError("Can't express 1-4 electrostatic scaling in Charmm file format")

    f = open(filename, "w")
    print("* prm file built by HTMD parameterize version {}".format(htmdversion()), file=f)
    print("*\n", file=f)

    print("BONDS", file=f)
    types = getSortedAndUniqueTypes(mol.atomtype[mol.bonds], 'bond_types')
    for type in types:
        val = getParameter(type, parameters.bond_types)
        print("%-6s %-6s %8.2f %8.4f" % (type[0], type[1], val.k, val.req), file=f)

    print("\nANGLES", file=f)
    types = getSortedAndUniqueTypes(mol.atomtype[mol.angles], 'angle_types')
    for type in types:
        val = getParameter(type, parameters.angle_types)
        print("%-6s %-6s %-6s %8.2f %8.2f" % (type[0], type[1], type[2], val.k, val.theteq), file=f)

    print("\nDIHEDRALS", file=f)
    types = getSortedAndUniqueTypes(mol.atomtype[mol.dihedrals], 'dihedral_types')
    for type in types:
        val = getParameter(type, parameters.dihedral_types)
        for term in val:
            print("%-6s %-6s %-6s %-6s %12.8f %d %12.8f" % (type[0], type[1], type[2], type[3], term.phi_k, term.per, term.phase), file=f)

    print("\nIMPROPER", file=f)
    types = getSortedAndUniqueTypes(mol.atomtype[mol.impropers], 'improper_types')
    for type in types:
        type, field = findImproperType(type, parameters)
        val = parameters.__dict__[field][type]
        if field == 'improper_periodic_types':
            for term in ensurelist(val):
                print("%-6s %-6s %-6s %-6s %12.8f %d %12.8f" % (type[0], type[1], type[2], type[3], term.phi_k, term.per, term.phase), file=f)
        elif field == 'improper_types':
            print("%-6s %-6s %-6s %-6s %12.8f %d %12.8f" % (type[0], type[1], type[2], type[3], val.psi_k, 0, val.psi_eq), file=f)

    print("\nNONBONDED nbxmod  5 atom cdiel shift vatom vdistance vswitch -", file=f)
    print("cutnb 14.0 ctofnb 12.0 ctonnb 10.0 eps 1.0 e14fac 1.0 wmin 1.5", file=f)
    types = getSortedAndUniqueTypes(mol.atomtype, 'atom_types')
    for type in types:
        val = parameters.atom_types[type]
        if val.epsilon_14 != val.epsilon:
            print("%-6s 0.0000 %8.4f %8.4f 0.0000 %8.4f %8.4f" % (type, val.epsilon, val.rmin, val.epsilon_14, val.rmin_14), file=f)
        else:
            print("%-6s 0.0000 %8.4f %8.4f" % (type, val.epsilon, val.rmin), file=f)
    f.close()
Exemple #2
0
def writeFRCMOD(mol, parameters, filename, typemap=None):
    from htmd.version import version as htmdversion
    if typemap is not None:
        parameters = mapAtomTypesParameterSet(parameters, typemap)
        atomtypes = np.vectorize(typemap.get)(mol.atomtype)
    else:
        atomtypes = mol.atomtype

    f = open(filename, "w")
    print("Frcmod generated by HTMD parameterize version {}".format(
        htmdversion()),
          file=f)
    print("MASS", file=f)
    for at in np.unique(atomtypes):
        print("%s %f %f" % (at, parameters.atom_types[at].mass, 0.), file=f)

    print("\nBOND", file=f)
    types = getSortedAndUniqueTypes(atomtypes[mol.bonds], 'bond_types')
    for type in types:
        val = getParameter(type, parameters.bond_types)
        print("%s %f %f" % ('-'.join(type), val.k, val.req), file=f)

    print("\nANGL", file=f)
    types = getSortedAndUniqueTypes(atomtypes[mol.angles], 'angle_types')
    for type in types:
        val = getParameter(type, parameters.angle_types)
        print("%s %f %f" % ('-'.join(type), val.k, val.theteq), file=f)

    print("\nDIHE", file=f)
    types = getSortedAndUniqueTypes(atomtypes[mol.dihedrals], 'dihedral_types')
    for type in types:
        val = getParameter(type, parameters.dihedral_types)

        toprint = []
        for term in val:
            if term.phi_k == 0:
                continue
            toprint.append(term)

        # HACK: print at least one dihedral, even if the force constant is 0, otherwise "tleap" is not happy!
        if len(toprint) == 0:
            toprint.append(val[0])

        for i, term in enumerate(toprint):
            # All terms of the same dihedral except the last one should be negative. http://ambermd.org/formats.html#frcmod
            if i == len(toprint) - 1:
                print("%s 1 %12.6f %12.6f %12.6f %12.6f %12.6f" %
                      ('-'.join(type), term.phi_k, term.phase, term.per,
                       term.scee, term.scnb),
                      file=f)
            else:
                print("%s 1 %12.6f %12.6f %12.6f %12.6f %12.6f" %
                      ('-'.join(type), term.phi_k, term.phase, -term.per,
                       term.scee, term.scnb),
                      file=f)

    print("\nIMPR", file=f)
    types = getSortedAndUniqueTypes(atomtypes[mol.impropers], 'improper_types')
    for type in types:
        val, field = getImproperParameter(type, parameters)
        if field == 'improper_periodic_types':
            if val.phi_k == 0:
                continue
            print("%s     %f %f %f" %
                  ('-'.join(type), val.phi_k, val.phase, val.per),
                  file=f)
        elif field == 'improper_types':
            if val.psi_k == 0:
                continue
            print("%s     %f %f %f" %
                  ('-'.join(type), val.psi_k, val.psi_eq, 1),
                  file=f)

    print("\nNONB", file=f)
    # Have to iterate over the types in use, which include cloned types, and map them back
    # to original type (which has the same vdw params), because a copy of a copy won't be in self.nonbonded.
    types = getSortedAndUniqueTypes(atomtypes, 'atom_types')
    for type in types:
        val = parameters.atom_types[type]
        print("%s %f %f" % (type, val.rmin, val.epsilon), file=f)

    print("", file=f)
    f.close()
Exemple #3
0
def writeFRCMOD(mol, parameters, filename, typemap=None):
    from htmd.version import version as htmdversion
    if typemap is not None:
        parameters = mapAtomTypesParameterSet(parameters, typemap)
        atomtypes = np.vectorize(typemap.get)(mol.atomtype)
    else:
        atomtypes = mol.atomtype

    f = open(filename, "w")
    f.write("Frcmod generated by HTMD parameterize version {}\n".format(htmdversion()))
    f.write("MASS\n")
    for at in np.unique(atomtypes):
        f.write('{:<2s}  {:>8.3f} {:>10.2f}\n'.format(at, parameters.atom_types[at].mass, 0.))

    f.write('\nBOND\n')
    types = getSortedAndUniqueTypes(atomtypes[mol.bonds], 'bond_types')
    for type in types:
        val = getParameter(type, parameters.bond_types)
        f.write('{:<2s}-{:<2s} {:>10.3f}{:>8.3f}\n'.format(type[0], type[1], val.k, val.req))

    f.write('\nANGL\n')
    types = getSortedAndUniqueTypes(atomtypes[mol.angles], 'angle_types')
    for type in types:
        val = getParameter(type, parameters.angle_types)
        f.write('{:<2s}-{:<2s}-{:<2s} {:>10.3f}{:>9.3f}\n'.format(type[0], type[1], type[2], val.k, val.theteq))

    f.write('\nDIHE\n')
    types = getSortedAndUniqueTypes(atomtypes[mol.dihedrals], 'dihedral_types')
    for type in types:
        val = getParameter(type, parameters.dihedral_types)

        toprint = []
        for term in val:
            if term.phi_k < 1e-6:
                continue
            toprint.append(term)

        # HACK: print at least one dihedral, even if the force constant is 0, otherwise "tleap" is not happy!
        if len(toprint) == 0:
            toprint.append(val[0])

        for i, term in enumerate(toprint):
            # All terms of the same dihedral except the last one should be negative. http://ambermd.org/formats.html#frcmod
            per = term.per
            if i != len(toprint)-1:
                per = -per
            fmt = '{:<2s}-{:<2s}-{:<2s}-{:<2s} {:>4d}{:>15.8f}{:>9.3f}{:>6.1f}    SCEE={:1.1f} SCNB={:1.1f}\n'
            f.write(fmt.format(type[0], type[1], type[2], type[3], 1, term.phi_k, term.phase, per, term.scee, term.scnb))

    f.write('\nIMPR\n')
    types = getSortedAndUniqueTypes(atomtypes[mol.impropers], 'improper_types')
    for type in types:
        type, field = findImproperType(type, parameters)
        val = parameters.__dict__[field][type]
        fmt = '{:<2s}-{:<2s}-{:<2s}-{:<2s}     {:>10.8f}{:>9.3f}{:>6.1f}\n'
        if field == 'improper_periodic_types':
            if val.phi_k < 1e-6:
                continue
            f.write(fmt.format(type[0], type[1], type[2], type[3], val.phi_k, val.phase, val.per))
        elif field == 'improper_types':
            if val.psi_k < 1e-6:
                continue
            f.write(fmt.format(type[0], type[1], type[2], type[3], val.psi_k, val.psi_eq, 1))

    f.write('\nNONB\n')
    # Have to iterate over the types in use, which include cloned types, and map them back
    # to original type (which has the same vdw params), because a copy of a copy won't be in self.nonbonded.
    types = getSortedAndUniqueTypes(atomtypes, 'atom_types')
    for type in types:
        val = parameters.atom_types[type]
        f.write('{:<2s}    {:>10.8f}   {:>10.8f}\n'.format(type, val.rmin, val.epsilon))
    f.write('\n')
    f.close()
Exemple #4
0
def writeFRCMOD(mol, parameters, filename, typemap=None):
    from htmd.version import version as htmdversion
    if typemap is not None:
        parameters = mapAtomTypesParameterSet(parameters, typemap)
        atomtypes = np.vectorize(typemap.get)(mol.atomtype)
    else:
        atomtypes = mol.atomtype

    f = open(filename, "w")
    f.write("Frcmod generated by HTMD parameterize version {}\n".format(htmdversion()))
    f.write("MASS\n")
    for at in np.unique(atomtypes):
        f.write('{:<2s}  {:>8.3f} {:>10.2f}\n'.format(at, parameters.atom_types[at].mass, 0.))

    f.write('\nBOND\n')
    types = getSortedAndUniqueTypes(atomtypes[mol.bonds], 'bond_types')
    for type in types:
        val = getParameter(type, parameters.bond_types)
        f.write('{:<2s}-{:<2s} {:>10.3f}{:>8.3f}\n'.format(type[0], type[1], val.k, val.req))

    f.write('\nANGL\n')
    types = getSortedAndUniqueTypes(atomtypes[mol.angles], 'angle_types')
    for type in types:
        val = getParameter(type, parameters.angle_types)
        f.write('{:<2s}-{:<2s}-{:<2s} {:>10.3f}{:>9.3f}\n'.format(type[0], type[1], type[2], val.k, val.theteq))

    f.write('\nDIHE\n')
    types = getSortedAndUniqueTypes(atomtypes[mol.dihedrals], 'dihedral_types')
    for type in types:
        val = getParameter(type, parameters.dihedral_types)

        toprint = []
        for term in val:
            if term.phi_k == 0:
                continue
            toprint.append(term)

        # HACK: print at least one dihedral, even if the force constant is 0, otherwise "tleap" is not happy!
        if len(toprint) == 0:
            toprint.append(val[0])

        for i, term in enumerate(toprint):
            # All terms of the same dihedral except the last one should be negative. http://ambermd.org/formats.html#frcmod
            per = term.per
            if i != len(toprint)-1:
                per = -per
            fmt = '{:<2s}-{:<2s}-{:<2s}-{:<2s} {:>4d}{:>15.8f}{:>9.3f}{:>6.1f}    SCEE={:1.1f} SCNB={:1.1f}\n'
            f.write(fmt.format(type[0], type[1], type[2], type[3], 1, term.phi_k, term.phase, per, term.scee, term.scnb))

    f.write('\nIMPR\n')
    types = getSortedAndUniqueTypes(atomtypes[mol.impropers], 'improper_types')
    for type in types:
        val, field = getImproperParameter(type, parameters)
        fmt = '{:<2s}-{:<2s}-{:<2s}-{:<2s}     {:>10.8f}{:>9.3f}{:>6.1f}\n'
        if field == 'improper_periodic_types':
            if val.phi_k == 0:
                continue
            f.write(fmt.format(type[0], type[1], type[2], type[3], val.phi_k, val.phase, val.per))
        elif field == 'improper_types':
            if val.psi_k == 0:
                continue
            f.write(fmt.format(type[0], type[1], type[2], type[3], val.psi_k, val.psi_eq, 1))

    f.write('\nNONB\n')
    # Have to iterate over the types in use, which include cloned types, and map them back
    # to original type (which has the same vdw params), because a copy of a copy won't be in self.nonbonded.
    types = getSortedAndUniqueTypes(atomtypes, 'atom_types')
    for type in types:
        val = parameters.atom_types[type]
        f.write('{:<2s}    {:>10.8f}   {:>10.8f}\n'.format(type, val.rmin, val.epsilon))
    f.write('\n')
    f.close()