From 02fd0e9443dfbfdd8048b9d8a0615daf3ff0d695 Mon Sep 17 00:00:00 2001 From: James Krieger Date: Fri, 6 Oct 2023 15:52:21 +0200 Subject: [PATCH] add info test --- prody/tests/datafiles/__init__.py | 9 +- prody/tests/proteins/test_waterbridges.py | 105 ++++++++++++++++------ 2 files changed, 87 insertions(+), 27 deletions(-) diff --git a/prody/tests/datafiles/__init__.py b/prody/tests/datafiles/__init__.py index 4e6ce2df8..4c23c0ca3 100644 --- a/prody/tests/datafiles/__init__.py +++ b/prody/tests/datafiles/__init__.py @@ -91,7 +91,14 @@ 'file': 'pdb3enl.pdb', 'n_atoms': 7294, 'models': 1 - }, + }, + '3enl_addH': { + 'pdb': '3enl', + 'file': 'addH_pdb3enl.pdb', + 'n_atoms': 7641, + 'models': 1, + 'n_h': 3999 + }, '3enl_mmtf': { 'pdb': '3ENL', 'file': 'mmtf3enl.mmtf', diff --git a/prody/tests/proteins/test_waterbridges.py b/prody/tests/proteins/test_waterbridges.py index 0dc804cfd..efde613b1 100644 --- a/prody/tests/proteins/test_waterbridges.py +++ b/prody/tests/proteins/test_waterbridges.py @@ -16,62 +16,75 @@ LOGGER.verbosity = 'none' -PATH_1UBI = pathDatafile('1ubi') -SPLIT_PATH = os.path.split(PATH_1UBI) +PATH_PDB = pathDatafile('3enl_addH') +SPLIT_PATH = os.path.split(PATH_PDB) TARGET_PATH = os.path.join(SPLIT_PATH[0], 'wb_cluster_' + SPLIT_PATH[1]) class TestWaterBridges(unittest.TestCase): def setUp(self): """Parse the PDB file and run the core calculations.""" - self.atoms = parseDatafile('1ubi_addH') - self.waterBridgesChain = calcWaterBridges(self.atoms) - self.waterBridgesClust = calcWaterBridges(self.atoms, method='cluster') + self.atoms = parsePDB(PATH_PDB) + if prody.PY3K: + self.waterBridgesChain = calcWaterBridges(self.atoms) + self.chainMultiWater = self.waterBridgesChain[37] + + self.waterBridgesClust = calcWaterBridges(self.atoms, method='cluster') + self.clustMultiWater = self.waterBridgesClust[36] + + self.waterBridgesClustInfo = calcWaterBridges(self.atoms, method='cluster', + output='info') + self.clustInfoMultiWater = self.waterBridgesClustInfo[36] + + self.pro0 = self.clustMultiWater.proteins[0] + self.pro1 = self.clustMultiWater.proteins[1] + self.w0 = self.clustMultiWater.waters[0] + self.w1 = self.clustMultiWater.waters[1] + @dec.slow def testSingleWaterBridgesChain(self): if prody.PY3K: self.assertIsInstance(self.waterBridgesChain, list, - 'calcWaterBridges output should be a list') + 'calcWaterBridges chain output should be a list') - self.assertEqual(len(self.waterBridgesChain), 7, - 'calcWaterBridges chain list should have 7 items') + self.assertEqual(len(self.waterBridgesChain), 77, + 'calcWaterBridges chain list should have 77 items') - chain0 = self.waterBridgesChain[1] - self.assertIsInstance(chain0, prody.proteins.waterbridges.AtomicOutput, + + self.assertIsInstance(self.chainMultiWater, prody.proteins.waterbridges.AtomicOutput, 'calcWaterBridges output should contain AtomicOutput') - self.assertEqual(len(chain0.proteins), 2, + self.assertEqual(len(self.chainMultiWater.proteins), 2, 'water bridges chains should have 2 protein items') - self.assertIsInstance(chain0.proteins[0], Atom, + self.assertIsInstance(self.chainMultiWater.proteins[0], Atom, 'protein items in water bridges chains should be Atom') - self.assertEqual(len(chain0.waters), 1, - 'water bridges chain should have 1 waters item') - self.assertIsInstance(chain0.waters[0], Atom, + self.assertEqual(len(self.chainMultiWater.waters), 2, + 'water bridges chain should have 2 water items') + self.assertIsInstance(self.chainMultiWater.waters[0], Atom, 'waters items in water bridges chains should be Atom') @dec.slow def testSingleWaterBridgesCluster(self): if prody.PY3K: self.assertIsInstance(self.waterBridgesClust, list, - 'calcWaterBridges output should be a list') + 'calcWaterBridges clust output should be a list') - self.assertEqual(len(self.waterBridgesClust), 7, - 'calcWaterBridges clust list should have 7 items') + self.assertEqual(len(self.waterBridgesClust), 74, + 'calcWaterBridges clust list should have 74 items') - clust1 = self.waterBridgesClust[1] - self.assertIsInstance(clust1, prody.proteins.waterbridges.AtomicOutput, + self.assertIsInstance(self.clustMultiWater, prody.proteins.waterbridges.AtomicOutput, 'calcWaterBridges output should contain AtomicOutput') - self.assertEqual(len(clust1.proteins), 3, - 'some water bridges clusters should have 3 protein items') - self.assertIsInstance(clust1.proteins[0], Atom, + self.assertEqual(len(self.clustMultiWater.proteins), 2, + 'tested water bridges multi-water cluster should have 3 protein items') + self.assertIsInstance(self.clustMultiWater.proteins[0], Atom, 'protein items in water bridges clusters should be Atom') - self.assertEqual(len(clust1.waters), 1, - 'water bridges cluster should have 1 waters item') - self.assertIsInstance(clust1.waters[0], Atom, + self.assertEqual(len(self.clustMultiWater.waters), 2, + 'tested water bridges multi-water cluster should have 2 waters items') + self.assertIsInstance(self.clustMultiWater.waters[0], Atom, 'waters items in water bridges clusters should be Atom') @dec.slow @@ -89,3 +102,43 @@ def testSaveWaterBridges(self): self.assertFalse(np.equal(self.atoms.water.numAtoms(), self.saved.water.numAtoms()), 'savePDBWaterBridges did not change the number of water atoms') + @dec.slow + def testSingleWaterBridgesOutputInfo(self): + if prody.PY3K: + self.assertIsInstance(self.waterBridgesClustInfo, list, + 'calcWaterBridges clust info output should be a list') + + self.assertEqual(len(self.waterBridgesClustInfo), 74, + 'calcWaterBridges clust info list should have 74 items') + + self.assertIsInstance(self.clustInfoMultiWater, list, + 'tested water bridges multi-water cluster info output should contain lists') + + self.assertEqual(len(self.clustInfoMultiWater), 9, + 'tested water bridges multi-water cluster info should have 9 items') + self.assertIsInstance(self.clustInfoMultiWater[0], str, + 'info items in water bridges clusters should be str') + + + self.assertEqual(self.clustInfoMultiWater[0], self.pro0.getResname() + str(self.pro0.getResnum()), + 'item 0 from selected info should be resname + resnum of atom 0') + self.assertEqual(self.clustInfoMultiWater[1], self.pro0.getName() + '_' + str(self.pro0.getIndex()), + 'item 1 from selected info should be name + _ + index of atom 0') + self.assertEqual(self.clustInfoMultiWater[2], self.pro0.getChid(), + 'item 2 from selected info should be chid of atom 0') + + self.assertEqual(self.clustInfoMultiWater[3], self.pro1.getResname() + str(self.pro1.getResnum()), + 'item 3 from selected info should be resname + resnum of atom 1') + self.assertEqual(self.clustInfoMultiWater[4], self.pro1.getName() + '_' + str(self.pro1.getIndex()), + 'item 4 from selected info should be name + _ + index of atom 1') + self.assertEqual(self.clustInfoMultiWater[5], self.pro1.getChid(), + 'item 5 from selected info should be chid of atom 1') + + self.assertEqual(self.clustInfoMultiWater[6], calcDistance(self.pro0, self.pro1), + 'item 6 from selected info should be distance from protein atom 0 to protein atom 1') + self.assertEqual(self.clustInfoMultiWater[7], len(self.clustMultiWater.waters), + 'item 7 from selected info should be number of waters in the cluster') + self.assertEqual(self.clustInfoMultiWater[8], + list(map(lambda w: f"{w.getChid()}_{w.getIndex()}", self.clustMultiWater.waters)), + 'item 8 from selected info should be chid and index for 2 water atoms') +