Commit 1f6e10d5 authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

changes

parent 659631da
Loading
Loading
Loading
Loading
+77 −69
Original line number Diff line number Diff line
@@ -4,8 +4,6 @@ Tests for Coulomb matrix calculation.
import numpy as np
import unittest

from rdkit import Chem

from deepchem.feat import coulomb_matrices as cm
from deepchem.utils import conformers

@@ -14,11 +12,13 @@ class TestCoulombMatrix(unittest.TestCase):
  """
    Tests for CoulombMatrix.
    """

  def setUp(self):
    """
        Set up tests.
        """
    smiles = 'CC(=O)OC1=CC=CC=C1C(=O)O'
    from rdkit import Chem
    mol = Chem.MolFromSmiles(smiles)
    engine = conformers.ConformerGenerator(max_conformers=1)
    self.mol = engine.generate_conformers(mol)
@@ -30,7 +30,8 @@ class TestCoulombMatrix(unittest.TestCase):
        """
    f = cm.CoulombMatrix(self.mol.GetNumAtoms())
    rval = f([self.mol])
        assert rval.shape == (1, self.mol.GetNumConformers(), self.mol.GetNumAtoms(), self.mol.GetNumAtoms())
    assert rval.shape == (1, self.mol.GetNumConformers(),
                          self.mol.GetNumAtoms(), self.mol.GetNumAtoms())

  def test_coulomb_matrix_padding(self):
    """
@@ -63,10 +64,11 @@ class TestCoulombMatrix(unittest.TestCase):
    """
        Test hydrogen removal.
        """
    from rdkit import Chem
    mol = Chem.RemoveHs(self.mol)
    assert mol.GetNumAtoms() < self.mol.GetNumAtoms()
        f = cm.CoulombMatrix(max_atoms=mol.GetNumAtoms(),
                             remove_hydrogens=True, upper_tri=True)
    f = cm.CoulombMatrix(
        max_atoms=mol.GetNumAtoms(), remove_hydrogens=True, upper_tri=True)
    rval = f([self.mol])  # use the version with hydrogens
    size = np.triu_indices(mol.GetNumAtoms())[0].size
    assert rval.shape == (1, mol.GetNumConformers(), size)
@@ -75,21 +77,26 @@ class TestCoulombMatrix(unittest.TestCase):
    """
        Test no hydrogen removal.
        """
        f = cm.CoulombMatrix(max_atoms=self.mol.GetNumAtoms(),
                             remove_hydrogens=False, upper_tri=True)
    f = cm.CoulombMatrix(
        max_atoms=self.mol.GetNumAtoms(),
        remove_hydrogens=False,
        upper_tri=True)
    rval = f([self.mol])
    size = np.triu_indices(self.mol.GetNumAtoms())[0].size
    assert rval.shape == (1, self.mol.GetNumConformers(), size)


class TestCoulombMatrixEig(unittest.TestCase):
  """
    Tests for CoulombMatrixEig.
    """

  def setUp(self):
    """
        Set up tests.
        """
    smiles = '[H]C([H])([H])[H]'
    from rdkit import Chem
    mol = Chem.MolFromSmiles(smiles)
    mol = Chem.AddHs(mol)
    engine = conformers.ConformerGenerator(max_conformers=1)
@@ -102,7 +109,8 @@ class TestCoulombMatrixEig(unittest.TestCase):
        """
    f = cm.CoulombMatrixEig(self.mol.GetNumAtoms())
    rval = f([self.mol])
        assert rval.shape == (1, self.mol.GetNumConformers(), self.mol.GetNumAtoms())
    assert rval.shape == (1, self.mol.GetNumConformers(),
                          self.mol.GetNumAtoms())

  def test_coulomb_matrix_eig_padding(self):
    """
+30 −31
Original line number Diff line number Diff line
@@ -2,9 +2,6 @@
Test topological fingerprints.
"""
import unittest

from rdkit import Chem

from deepchem.feat import fingerprints as fp


@@ -12,11 +9,13 @@ class TestCircularFingerprint(unittest.TestCase):
  """
    Tests for CircularFingerprint.
    """

  def setUp(self):
    """
        Set up tests.
        """
    smiles = 'CC(=O)OC1=CC=CC=C1C(=O)O'
    from rdkit import Chem
    self.mol = Chem.MolFromSmiles(smiles)
    self.engine = fp.CircularFingerprint()

+3 −1
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@ import unittest
import os
import sys
import numpy as np
import rdkit
from deepchem.feat.mol_graphs import ConvMol
from deepchem.feat.mol_graphs import MultiConvMol
from deepchem.feat.graph_features import ConvMolFeaturizer
@@ -28,6 +27,7 @@ class TestConvMolFeaturizer(unittest.TestCase):
    # Note there is a central nitrogen of degree 4, with 4 carbons
    # of degree 1 (connected only to central nitrogen).
    raw_smiles = ['C[N+](C)(C)C']
    import rdkit
    mols = [rdkit.Chem.MolFromSmiles(s) for s in raw_smiles]
    featurizer = ConvMolFeaturizer()
    mols = featurizer.featurize(mols)
@@ -53,6 +53,7 @@ class TestConvMolFeaturizer(unittest.TestCase):
  def test_single_carbon(self):
    """Test that single carbon atom is featurized properly."""
    raw_smiles = ['C']
    import rdkit
    mols = [rdkit.Chem.MolFromSmiles(s) for s in raw_smiles]
    featurizer = ConvMolFeaturizer()
    mol_list = featurizer.featurize(mols)
@@ -74,6 +75,7 @@ class TestConvMolFeaturizer(unittest.TestCase):
  def test_alkane(self):
    """Test on simple alkane"""
    raw_smiles = ['CCC']
    import rdkit
    mols = [rdkit.Chem.MolFromSmiles(s) for s in raw_smiles]
    featurizer = ConvMolFeaturizer()
    mol_list = featurizer.featurize(mols)
+4 −5
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@ import unittest
import os
import sys
import numpy as np
import rdkit
from deepchem.feat.mol_graphs import ConvMol
from deepchem.feat.mol_graphs import MultiConvMol

@@ -66,10 +65,10 @@ class TestMolGraphs(unittest.TestCase):
    # atom 2 has 2 neighbors
    # atom 3 has 3 neighbors.
    # Verify that atom features have been sorted by atom degree.
    assert np.array_equal(mol.get_atom_features(),
                          np.array([[56, 57, 58, 59], [40, 41, 42, 43],
                                    [44, 45, 46, 47], [48, 49, 50,
                                                       51], [52, 53, 54, 55]]))
    assert np.array_equal(
        mol.get_atom_features(),
        np.array([[56, 57, 58, 59], [40, 41, 42, 43], [44, 45, 46, 47],
                  [48, 49, 50, 51], [52, 53, 54, 55]]))

  def test_get_adjacency_list(self):
    """Tests that adj-list is canonicalized properly."""
+3 −4
Original line number Diff line number Diff line
@@ -7,10 +7,6 @@ import unittest

import numpy as np
np.random.seed(123)

from rdkit.Chem import MolFromSmiles
from rdkit.Chem.AllChem import Mol, ComputeGasteigerCharges

from deepchem.feat import rdkit_grid_featurizer as rgf


@@ -35,6 +31,7 @@ class TestHelperFunctions(unittest.TestCase):

  def test_load_molecule(self):
    # adding hydrogens and charges is tested in dc.utils
    from rdkit.Chem.AllChem import Mol
    for add_hydrogens in (True, False):
      for calc_charges in (True, False):
        mol_xyz, mol_rdk = rgf.load_molecule(self.ligand_file, add_hydrogens,
@@ -173,6 +170,7 @@ class TestHelperFunctions(unittest.TestCase):
          self.assertTrue((v2 == v_pair[1]).all())

  def test_compute_charge_dictionary(self):
    from rdkit.Chem.AllChem import ComputeGasteigerCharges
    for fname in (self.ligand_file, self.protein_file):
      _, mol = rgf.load_molecule(fname)
      ComputeGasteigerCharges(mol)
@@ -189,6 +187,7 @@ class TestPiInteractions(unittest.TestCase):
    current_dir = os.path.dirname(os.path.realpath(__file__))

    # simple flat ring
    from rdkit.Chem import MolFromSmiles
    self.cycle4 = MolFromSmiles('C1CCC1')
    self.cycle4.Compute2DCoords()

Loading