Exemple #1
0
def _dihedral_types_from_pmd(structure, dihedral_types_member_map=None):
    """Convert ParmEd dihedral types to GMSO DihedralType.

    This function take in a Parmed Structure, iterate through its
    dihedral_types and rb_torsion_types, create a corresponding
    GMSO.DihedralType, and finally return a dictionary containing all
    pairs of pmd.Dihedraltype (or pmd.RBTorsionType) and GMSO.DihedralType

    Parameters
    ----------
    structure: pmd.Structure
        Parmed Structure that needed to be converted.
    dihedral_types_member_map: optional, dict, default=None
        The member types (atomtype string) for each atom associated with the dihedral_types the structure

    Returns
    -------
    pmd_top_dihedraltypes : dict
        A dictionary linking a pmd.DihedralType or pmd.RBTorsionType
        object to its corresponding GMSO.DihedralType object.
    """
    pmd_top_dihedraltypes = dict()
    dihedral_types_member_map = _assert_dict(
        dihedral_types_member_map, "dihedral_types_member_map"
    )

    for dihedraltype in structure.dihedral_types:
        dihedral_params = {
            "k": (dihedraltype.phi_k * u.Unit("kcal / mol")),
            "phi_eq": (dihedraltype.phase * u.degree),
            "n": dihedraltype.per * u.dimensionless,
        }
        member_types = dihedral_types_member_map.get(id(dihedraltype))
        top_dihedraltype = gmso.DihedralType(
            parameters=dihedral_params, member_types=member_types
        )
        pmd_top_dihedraltypes[dihedraltype] = top_dihedraltype

    for dihedraltype in structure.rb_torsion_types:
        dihedral_params = {
            "c0": (dihedraltype.c0 * u.Unit("kcal/mol")),
            "c1": (dihedraltype.c1 * u.Unit("kcal/mol")),
            "c2": (dihedraltype.c2 * u.Unit("kcal/mol")),
            "c3": (dihedraltype.c3 * u.Unit("kcal/mol")),
            "c4": (dihedraltype.c4 * u.Unit("kcal/mol")),
            "c5": (dihedraltype.c5 * u.Unit("kcal/mol")),
        }

        member_types = dihedral_types_member_map.get(id(dihedraltype))

        top_dihedraltype = gmso.DihedralType(
            parameters=dihedral_params,
            expression="c0 * cos(phi)**0 + c1 * cos(phi)**1 + "
            + "c2 * cos(phi)**2 + c3 * cos(phi)**3 + c4 * cos(phi)**4 + "
            + "c5 * cos(phi)**5",
            independent_variables="phi",
            member_types=member_types,
        )
        pmd_top_dihedraltypes[dihedraltype] = top_dihedraltype
    return pmd_top_dihedraltypes
Exemple #2
0
def _dihedral_types_from_pmd(structure, dihedral_types_member_map=None):
    """ Helper function to convert GMSO DihedralType

    This function take in a Parmed Structure, iterate through its
    dihedral_types and rb_torsion_types, create a corresponding
    GMSO.DihedralType, and finally return a dictionary containing all
    pairs of pmd.Dihedraltype (or pmd.RBTorsionType) and GMSO.DihedralType

    Parameters
    ----------
    structure: pmd.Structure
        Parmed Structure that needed to be converted.
    dihedral_types_member_map: optional, dict, default=None
        The member types (atomtype string) for each atom associated with the dihedral_types the structure

    Returns
    -------
    pmd_top_dihedraltypes : dict
        A dictionary linking a pmd.DihedralType or pmd.RBTorsionType
        object to its corresponding GMSO.DihedralType object.
    """
    pmd_top_dihedraltypes = dict()
    dihedral_types_member_map = _assert_dict(dihedral_types_member_map,
                                             'dihedral_types_member_map')

    for dihedraltype in structure.dihedral_types:
        dihedral_params = {
            'k': (dihedraltype.phi_k * u.Unit('kcal / mol')),
            'phi_eq': (dihedraltype.phase * u.degree),
            'n': dihedraltype.per * u.dimensionless
        }
        member_types = dihedral_types_member_map.get(id(dihedraltype))
        top_dihedraltype = gmso.DihedralType(parameters=dihedral_params,
                                             member_types=member_types)
        pmd_top_dihedraltypes[dihedraltype] = top_dihedraltype

    for dihedraltype in structure.rb_torsion_types:
        dihedral_params = {
            'c0': (dihedraltype.c0 * u.Unit('kcal/mol')),
            'c1': (dihedraltype.c1 * u.Unit('kcal/mol')),
            'c2': (dihedraltype.c2 * u.Unit('kcal/mol')),
            'c3': (dihedraltype.c3 * u.Unit('kcal/mol')),
            'c4': (dihedraltype.c4 * u.Unit('kcal/mol')),
            'c5': (dihedraltype.c5 * u.Unit('kcal/mol')),
        }

        member_types = dihedral_types_member_map.get(id(dihedraltype))

        top_dihedraltype = gmso.DihedralType(
            parameters=dihedral_params,
            expression='c0 * cos(phi)**0 + c1 * cos(phi)**1 + ' +
            'c2 * cos(phi)**2 + c3 * cos(phi)**3 + c4 * cos(phi)**4 + ' +
            'c5 * cos(phi)**5',
            independent_variables='phi',
            member_types=member_types)
        pmd_top_dihedraltypes[dihedraltype] = top_dihedraltype
    return pmd_top_dihedraltypes
def _dihedral_types_from_pmd(structure):
    """ Helper function to convert GMSO DihedralType

    This function take in a Parmed Structure, iterate through its
    dihedral_types and rb_torsion_types, create a corresponding
    GMSO.DihedralType, and finally return a dictionary containing all
    pairs of pmd.Dihedraltype (or pmd.RBTorsionType) and GMSO.DihedralType

    Parameter
    ----------
        structure: pmd.Structure
            Parmed Structure that needed to be converted.

    Return
    ------
        pmd_top_dihedraltypes : dict
            A dictionary linking a pmd.DihedralType or pmd.RBTorsionType
            object to its corresponding GMSO.DihedralType object.
    """
    pmd_top_dihedraltypes = dict()
    for dihedraltype in structure.dihedral_types:
        dihedral_params = {
            'k': (dihedraltype.phi_k * u.Unit('kcal / mol')),
            'phi_eq': (dihedraltype.phase * u.degree),
            'n': dihedraltype.per * u.dimensionless
        }

        top_dihedraltype = gmso.DihedralType(parameters=dihedral_params)
        pmd_top_dihedraltypes[dihedraltype] = top_dihedraltype
    for dihedraltype in structure.rb_torsion_types:
        dihedral_params = {
            'c0': (dihedraltype.c0 * u.Unit('kcal/mol')),
            'c1': (dihedraltype.c1 * u.Unit('kcal/mol')),
            'c2': (dihedraltype.c2 * u.Unit('kcal/mol')),
            'c3': (dihedraltype.c3 * u.Unit('kcal/mol')),
            'c4': (dihedraltype.c4 * u.Unit('kcal/mol')),
            'c5': (dihedraltype.c5 * u.Unit('kcal/mol')),
        }

        top_dihedraltype = gmso.DihedralType(
            parameters=dihedral_params,
            expression='c0 * cos(phi)**0 + c1 * cos(phi)**1 + ' +
            'c2 * cos(phi)**2 + c3 * cos(phi)**3 + c4 * cos(phi)**4 + ' +
            'c5 * cos(phi)**5',
            independent_variables='phi')
        pmd_top_dihedraltypes[dihedraltype] = top_dihedraltype
    return pmd_top_dihedraltypes
Exemple #4
0
def convert_ryckaert_to_opls(ryckaert_connection_type):
    """Convert Ryckaert-Bellemans dihedral to OPLS.

    NOTE: the conventions defining the dihedral angle are different
    for OPLS and RB torsions. OPLS torsions are defined with
    phi_cis = 0 while RB torsions are defined as phi_trans = 0.
    """
    templates = PotentialTemplateLibrary()
    ryckaert_bellemans_torsion_potential = templates[
        "RyckaertBellemansTorsionPotential"]
    opls_torsion_potential = templates["OPLSTorsionPotential"]

    valid_connection_type = False
    if (ryckaert_connection_type.independent_variables ==
            ryckaert_bellemans_torsion_potential.independent_variables):
        if (sympy.simplify(ryckaert_connection_type.expression -
                           ryckaert_bellemans_torsion_potential.expression) ==
                0):
            valid_connection_type = True
    if not valid_connection_type:
        raise GMSOError("Cannot use convert_ryckaert_to_opls "
                        "function to convert a ConnectionType that is not an "
                        "RyckaertBellemansTorsionPotential")

    c0 = ryckaert_connection_type.parameters["c0"]
    c1 = ryckaert_connection_type.parameters["c1"]
    c2 = ryckaert_connection_type.parameters["c2"]
    c3 = ryckaert_connection_type.parameters["c3"]
    c4 = ryckaert_connection_type.parameters["c4"]
    c5 = ryckaert_connection_type.parameters["c5"]

    if c5 != 0.0:
        raise GMSOError("Cannot convert Ryckaert-Bellemans dihedral "
                        "to OPLS dihedral if c5 is not equal to zero.")

    converted_params = {
        "k0": 2.0 * (c0 + c1 + c2 + c3 + c4),
        "k1": (-2.0 * c1 - (3.0 / 2.0) * c3),
        "k2": (-c2 - c4),
        "k3": ((-1.0 / 2.0) * c3),
        "k4": ((-1.0 / 4.0) * c4),
    }

    name = opls_torsion_potential.name
    expression = opls_torsion_potential.expression
    variables = opls_torsion_potential.independent_variables

    opls_connection_type = gmso.DihedralType(
        name=name,
        expression=expression,
        independent_variables=variables,
        parameters=converted_params,
    )

    return opls_connection_type
Exemple #5
0
def convert_ryckaert_to_opls(ryckaert_connection_type):
    """Convert Ryckaert-Bellemans dihedral to OPLS

    NOTE: the conventions defining the dihedral angle are different
    for OPLS and RB torsions. OPLS torsions are defined with
    phi_cis = 0 while RB torsions are defined as phi_trans = 0.
    """
    templates = PotentialTemplateLibrary()
    ryckaert_bellemans_torsion_potential = templates[
        'RyckaertBellemansTorsionPotential']
    opls_torsion_potential = templates['OPLSTorsionPotential']

    valid_connection_type = False
    if (ryckaert_connection_type.independent_variables ==
            ryckaert_bellemans_torsion_potential.independent_variables):
        if sympy.simplify(
                ryckaert_connection_type.expression -
                ryckaert_bellemans_torsion_potential.expression) == 0:
            valid_connection_type = True
    if not valid_connection_type:
        raise GMSOError('Cannot use convert_ryckaert_to_opls '
                        'function to convert a ConnectionType that is not an '
                        'RyckaertBellemansTorsionPotential')

    c0 = ryckaert_connection_type.parameters['c0']
    c1 = ryckaert_connection_type.parameters['c1']
    c2 = ryckaert_connection_type.parameters['c2']
    c3 = ryckaert_connection_type.parameters['c3']
    c4 = ryckaert_connection_type.parameters['c4']
    c5 = ryckaert_connection_type.parameters['c5']

    if c5 != 0.0:
        raise GMSOError('Cannot convert Ryckaert-Bellemans dihedral '
                        'to OPLS dihedral if c5 is not equal to zero.')

    converted_params = {
        'k0': 2. * (c0 + c1 + c2 + c3 + c4),
        'k1': (-2. * c1 - (3. / 2.) * c3),
        'k2': (-c2 - c4),
        'k3': ((-1. / 2.) * c3),
        'k4': ((-1. / 4.) * c4)
    }

    name = opls_torsion_potential.name
    expression = opls_torsion_potential.expression
    variables = opls_torsion_potential.independent_variables

    opls_connection_type = gmso.DihedralType(name=name,
                                             expression=expression,
                                             independent_variables=variables,
                                             parameters=converted_params)

    return opls_connection_type
Exemple #6
0
def convert_opls_to_ryckaert(opls_connection_type):
    """Convert an OPLS dihedral to Ryckaert-Bellemans dihedral.

    Equations taken/modified from:
        http://manual.gromacs.org/documentation/2019/
        reference-manual/functions/bonded-interactions.html

    NOTE: the conventions defining the dihedral angle are different
    for OPLS and RB torsions. OPLS torsions are defined with
    phi_cis = 0 while RB torsions are defined as phi_trans = 0.
    """
    templates = PotentialTemplateLibrary()
    opls_torsion_potential = templates["OPLSTorsionPotential"]
    valid_connection_type = False
    if (opls_connection_type.independent_variables ==
            opls_torsion_potential.independent_variables):
        if (sympy.simplify(opls_connection_type.expression -
                           opls_torsion_potential.expression) == 0):
            valid_connection_type = True
    if not valid_connection_type:
        raise GMSOError("Cannot use convert_opls_to_ryckaert "
                        "function to convert a ConnectionType that is not an "
                        "OPLSTorsionPotential")

    f0 = opls_connection_type.parameters["k0"]
    f1 = opls_connection_type.parameters["k1"]
    f2 = opls_connection_type.parameters["k2"]
    f3 = opls_connection_type.parameters["k3"]
    f4 = opls_connection_type.parameters["k4"]

    converted_params = {
        "c0": (f2 + 0.5 * (f0 + f1 + f3)),
        "c1": (0.5 * (-f1 + 3.0 * f3)),
        "c2": (-f2 + 4.0 * f4),
        "c3": (-2.0 * f3),
        "c4": (-4.0 * f4),
        "c5": 0.0 * u.Unit("kJ/mol"),
    }
    ryckaert_bellemans_torsion_potential = templates[
        "RyckaertBellemansTorsionPotential"]
    name = ryckaert_bellemans_torsion_potential.name
    expression = ryckaert_bellemans_torsion_potential.expression
    variables = ryckaert_bellemans_torsion_potential.independent_variables

    ryckaert_connection_type = gmso.DihedralType(
        name=name,
        expression=expression,
        independent_variables=variables,
        parameters=converted_params,
    )

    return ryckaert_connection_type
Exemple #7
0
def convert_opls_to_ryckaert(opls_connection_type):
    """Convert an OPLS dihedral to Ryckaert-Bellemans dihedral

    Equations taken/modified from:
        http://manual.gromacs.org/documentation/2019/
        reference-manual/functions/bonded-interactions.html

    NOTE: the conventions defining the dihedral angle are different
    for OPLS and RB torsions. OPLS torsions are defined with
    phi_cis = 0 while RB torsions are defined as phi_trans = 0.
    """
    templates = PotentialTemplateLibrary()
    opls_torsion_potential = templates['OPLSTorsionPotential']
    valid_connection_type = False
    if (opls_connection_type.independent_variables ==
            opls_torsion_potential.independent_variables):
        if sympy.simplify(opls_connection_type.expression -
                          opls_torsion_potential.expression) == 0:
            valid_connection_type = True
    if not valid_connection_type:
        raise GMSOError('Cannot use convert_opls_to_ryckaert '
                        'function to convert a ConnectionType that is not an '
                        'OPLSTorsionPotential')

    f0 = opls_connection_type.parameters['k0']
    f1 = opls_connection_type.parameters['k1']
    f2 = opls_connection_type.parameters['k2']
    f3 = opls_connection_type.parameters['k3']
    f4 = opls_connection_type.parameters['k4']

    converted_params = {
        'c0': (f2 + 0.5 * (f0 + f1 + f3)),
        'c1': (0.5 * (-f1 + 3. * f3)),
        'c2': (-f2 + 4. * f4),
        'c3': (-2. * f3),
        'c4': (-4. * f4),
        'c5': 0. * u.Unit('kJ/mol')
    }
    ryckaert_bellemans_torsion_potential = templates[
        'RyckaertBellemansTorsionPotential']
    name = ryckaert_bellemans_torsion_potential.name
    expression = ryckaert_bellemans_torsion_potential.expression
    variables = ryckaert_bellemans_torsion_potential.independent_variables

    ryckaert_connection_type = gmso.DihedralType(
        name=name,
        expression=expression,
        independent_variables=variables,
        parameters=converted_params)

    return ryckaert_connection_type