Example #1
0
 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)
     charge_dict = rgf.compute_charge_dictionary(mol)
     self.assertEqual(len(charge_dict), mol.GetNumAtoms())
     for i in range(mol.GetNumAtoms()):
       self.assertIn(i, charge_dict)
       self.assertIsInstance(charge_dict[i], (float, int))
Example #2
0
 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,
                                            calc_charges)
       num_atoms = mol_rdk.GetNumAtoms()
       self.assertIsInstance(mol_xyz, np.ndarray)
       self.assertIsInstance(mol_rdk, Mol)
       self.assertEqual(mol_xyz.shape, (num_atoms, 3))
Example #3
0
  def setUp(self):
    current_dir = os.path.dirname(os.path.realpath(__file__))

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

    # load and sanitize two real molecules
    _, self.prot = rgf.load_molecule(
        os.path.join(current_dir, 'data', '3ws9_protein_fixer_rdkit.pdb'),
        add_hydrogens=False,
        calc_charges=False,
        sanitize=True)

    _, self.lig = rgf.load_molecule(
        os.path.join(current_dir, 'data', '3ws9_ligand.sdf'),
        add_hydrogens=False,
        calc_charges=False,
        sanitize=True)
Example #4
0
  def test_featurize_splif(self):
    prot_xyz, prot_rdk = rgf.load_molecule(self.protein_file)
    lig_xyz, lig_rdk = rgf.load_molecule(self.ligand_file)
    distance = rgf.compute_pairwise_distances(
        protein_xyz=prot_xyz, ligand_xyz=lig_xyz)

    bins = [(1, 2), (2, 3)]

    dicts = rgf.featurize_splif(
        prot_xyz,
        prot_rdk,
        lig_xyz,
        lig_rdk,
        contact_bins=bins,
        pairwise_distances=distance,
        ecfp_degree=2)
    expected_dicts = [
        rgf.compute_splif_features_in_range(
            prot_rdk, lig_rdk, distance, c_bin, ecfp_degree=2) for c_bin in bins
    ]
    self.assertIsInstance(dicts, list)
    self.assertEqual(dicts, expected_dicts)
Example #5
0
  def test_compute_all_ecfp(self):
    _, mol = rgf.load_molecule(self.ligand_file)
    num_atoms = mol.GetNumAtoms()
    for degree in range(1, 4):
      # TODO test if dict contains smiles

      ecfp_all = rgf.compute_all_ecfp(mol, degree=degree)
      self.assertIsInstance(ecfp_all, dict)
      self.assertEqual(len(ecfp_all), num_atoms)
      self.assertEqual(list(ecfp_all.keys()), list(range(num_atoms)))

      num_ind = np.random.choice(range(1, num_atoms))
      indices = list(np.random.choice(num_atoms, num_ind, replace=False))

      ecfp_selected = rgf.compute_all_ecfp(mol, indices=indices, degree=degree)
      self.assertIsInstance(ecfp_selected, dict)
      self.assertEqual(len(ecfp_selected), num_ind)
      self.assertEqual(sorted(ecfp_selected.keys()), sorted(indices))