Ejemplo n.º 1
0
    def test_add_dance_property_appends_to_empty_list(self):
        mol, prop = oechem.OEMol(), danceprops.DanceProperties()
        props = []
        danceprops.add_dance_property(mol, prop, props)

        assert len(props) == 1
        assert mol.GetData(danceprops.DANCE_PROPS_KEY) == 0
        assert props[-1] == prop
Ejemplo n.º 2
0
    def test_add_dance_property_appends_to_small_list(
            self, small_mols_and_props_list):
        mols, props = small_mols_and_props_list
        mol, prop = oechem.OEMol(), danceprops.DanceProperties()
        mols.append(mol)
        danceprops.add_dance_property(mol, prop, props)

        assert len(props) == 5
        assert mol.GetData(danceprops.DANCE_PROPS_KEY) == 4
        assert props[-1] == prop
Ejemplo n.º 3
0
    def _calc_properties(mol: oechem.OEMol) -> danceprops.DanceProperties:
        """
        Calculates properties of the given molecule and returns a
        DanceProperties object holding them.

        Based on Victoria Lim's am1wib.py - see
        https://github.com/vtlim/misc/blob/master/oechem/am1wib.py
        """
        props = danceprops.DanceProperties()

        for conf in mol.GetConfs():
            charged_copy = oechem.OEMol(conf)
            results = oequacpac.OEAM1Results()
            if not AM1.CalcAM1(results, charged_copy):
                logging.debug(
                    f"failed to assign partial charges to {mol.GetTitle()}")
                return props
            DanceGenerator._add_charge_props(mol, charged_copy, results)

            # Sum bond orders, bond lengths, and bond angles
            for atom in charged_copy.GetAtoms(oechem.OEIsInvertibleNitrogen()):
                nbors = list(atom.GetAtoms())  # (neighbors)
                ang1 = math.degrees(
                    oechem.OEGetAngle(charged_copy, nbors[0], atom, nbors[1]))
                ang2 = math.degrees(
                    oechem.OEGetAngle(charged_copy, nbors[1], atom, nbors[2]))
                ang3 = math.degrees(
                    oechem.OEGetAngle(charged_copy, nbors[2], atom, nbors[0]))
                props.tri_n_bond_angle = ang1 + ang2 + ang3

                for nbor in nbors:
                    bond_order = results.GetBondOrder(atom.GetIdx(),
                                                      nbor.GetIdx())
                    bond_length = oechem.OEGetDistance(charged_copy, atom,
                                                       nbor)
                    element = nbor.GetAtomicNum()

                    props.tri_n_bonds.append(
                        danceprops.DanceTriNBond(bond_order, bond_length,
                                                 element))
                    props.tri_n_bond_order += bond_order
                    props.tri_n_bond_length += bond_length

                break  # terminate after one trivalent nitrogen
            break  # terminate after one conformation

        return props
Ejemplo n.º 4
0
    def test_append_properties_list_appends_small_list(
            self, small_mols_and_props_list):
        old_mols, old_props = small_mols_and_props_list
        mols, props = old_mols.copy(), old_props.copy()

        mols2 = [oechem.OEMol() for i in range(2)]
        oechem.OESmilesToMol(mols2[0], "CN=C=O")
        oechem.OESmilesToMol(mols2[1], "[C-]#[O+]")
        danceprops.set_dance_property(mols2[0], 1)
        danceprops.set_dance_property(mols2[1], 0)
        old_mols2 = [oechem.OEMol(m) for m in mols2]
        props2 = [danceprops.DanceProperties() for i in range(2)]

        danceprops.append_properties_list(mols, props, mols2, props2)

        # The properties obtained from the molecules put in the new list should
        # be the same as the properties in the old list.
        assert danceprops.get_dance_property(
            mols[4],
            props) == danceprops.get_dance_property(old_mols2[0], props2)
        assert danceprops.get_dance_property(
            mols[5],
            props) == danceprops.get_dance_property(old_mols2[1], props2)
Ejemplo n.º 5
0
def small_mols_and_props_list() -> ([oechem.OEMol],
                                    [danceprops.DanceProperties]):
    """
    Returns a list of 4 molecules, as well as another list with their 4
    corresponding properties. Note that the properties are actually empty.

    Molecules will be as follows - the index of their properties in the props
    list is given in parens:
    [ N (2), N#N (3), O=C=O (0), C#N (1) ]
    """
    # yapf: enable
    smiles = ["N", "N#N", "O=C=O", "C#N"]
    mols = [oechem.OEMol() for _ in range(4)]
    for i in range(4):
        oechem.OESmilesToMol(mols[i], smiles[i])

    mols[0].SetData(danceprops.DANCE_PROPS_KEY, 2)
    mols[1].SetData(danceprops.DANCE_PROPS_KEY, 3)
    mols[2].SetData(danceprops.DANCE_PROPS_KEY, 0)
    mols[3].SetData(danceprops.DANCE_PROPS_KEY, 1)

    props = [danceprops.DanceProperties() for _ in range(4)]

    return (mols, props)