Skip to content

Commit

Permalink
Utilities test case added
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranavkhade committed Jan 18, 2024
1 parent 082eed6 commit 98d9067
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packman/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@


#VERSION CHANGE HERE CHANGES IT IN docs AND setup.py
__version__='1.4.10'
__version__='1.4.11'
2 changes: 1 addition & 1 deletion packman/tests/anm/test_anm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
from os import remove as rm

class TestMolecule(unittest.TestCase):
class Test_ANM(unittest.TestCase):

def setUp(self):
self.mol = molecule.load_structure('packman/tests/data/4hla.cif',ftype='cif')
Expand Down
2 changes: 1 addition & 1 deletion packman/tests/dci/test_dci.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
from os import remove as rm

class TestMolecule(unittest.TestCase):
class Test_DCI(unittest.TestCase):

def setUp(self):
self.mol = molecule.load_structure('packman/tests/data/4hla.cif',ftype='cif')
Expand Down
2 changes: 1 addition & 1 deletion packman/tests/entropy/test_entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
from os import remove as rm

class TestMolecule(unittest.TestCase):
class Test_Entropy(unittest.TestCase):

def setUp(self):
self.mol = molecule.load_structure('packman/tests/data/4hla.cif',ftype='cif')
Expand Down
4 changes: 2 additions & 2 deletions packman/tests/geometry/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
from os import remove as rm

class TestGeometry(unittest.TestCase):
class Test_Geometry(unittest.TestCase):

def setUp(self):
self.mol = molecule.load_structure('packman/tests/data/4hla.cif',ftype='cif')
Expand All @@ -25,7 +25,7 @@ def test_AlphaShape(self):
self.assertIsInstance( geometry.AlphaShape( [j for i in self.mol[0].get_backbone() for j in i], 4 )[0][0][0], molecule.Atom )

def tearDown(self):
logging.info('Molecule Test Done.')
logging.info('Geometry Test Done.')

if(__name__=='__main__'):
unittest.main()
2 changes: 1 addition & 1 deletion packman/tests/gnm/test_gnm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
from os import remove as rm

class TestMolecule(unittest.TestCase):
class Test_GNM(unittest.TestCase):

def setUp(self):
self.mol = molecule.load_structure('packman/tests/data/4hla.cif',ftype='cif')
Expand Down
2 changes: 1 addition & 1 deletion packman/tests/molecule/test_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
from os import remove as rm

class TestMolecule(unittest.TestCase):
class Test_Molecule(unittest.TestCase):

def setUp(self):
self.mol = molecule.load_structure('packman/tests/data/4hla.cif',ftype='cif')
Expand Down
Empty file.
43 changes: 43 additions & 0 deletions packman/tests/utilities/test_utilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from ... import molecule, utilities, geometry
import unittest
import numpy

import logging
from os import remove as rm

class Test_Utilities(unittest.TestCase):

def setUp(self):
self.mol = molecule.load_structure('packman/tests/data/4hla.cif',ftype='cif')

def test_superimpose(self):
# Double check later.
expected_a1 = [[-4.99437660e-01, -8.66349433e-01, -8.26228195e-04], [-8.66349792e-01, 4.99437142e-01, 7.60871525e-04], [-2.46531567e-04, 1.09581052e-03, -9.99999369e-01]]
expected_b1 = [[-0.02974615, -0.02141248, 0.65529778]]

expected_a2 = [[ 9.99999994e-01, 6.44035795e-05, 8.82404191e-05], [-6.44835190e-05, 9.99999587e-01, 9.06225051e-04], [-8.81820186e-05, -9.06230736e-04, 9.99999585e-01]]
expected_b2 = [[ 6.31828525e-03, 9.14265397e-05, -4.94164731e-03]]

a1, b1 = utilities.superimporse(self.mol[0]['A'], self.mol[0]['B'], use='calpha')
self.assertTrue( numpy.allclose( a1, expected_a1, rtol=1e-14 ) )
self.assertTrue( numpy.allclose( b1, expected_b1, rtol=1e-14 ) )

# since superimpose change the coordinates, keep it mind for future debugging in case that is changed.
a2, b2 = utilities.superimporse(self.mol[0]['A'], self.mol[0]['B'], use='backbone')
self.assertTrue( numpy.allclose( a2, expected_a2, rtol=1e-14 ) )
self.assertTrue( numpy.allclose( b2, expected_b2, rtol=1e-14 ) )

def test_RMSD(self):
self.assertTrue( (utilities.RMSD(self.mol[0]['A'], self.mol[0]['B'], use='calpha') - 0.10400695339185048) < 0.001 )
self.assertTrue( (utilities.RMSD(self.mol[0]['A'], self.mol[0]['B'], use='backbone')- 0.11195505579911495) < 0.001 )

def test_WriteOBJ(self):
AS = geometry.AlphaShape([i for i in self.mol[0].get_atoms()], float('inf'))
utilities.WriteOBJ( self.mol[0].get_atoms(), AS[0], open('test.obj','wb') )

def tearDown(self):
logging.info('Utilities Test Done.')

if(__name__=='__main__'):
unittest.main()

19 changes: 11 additions & 8 deletions packman/utilities/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import logging
import numpy

from typing import TYPE_CHECKING, List, Tuple, Dict
from typing import TYPE_CHECKING, List, Tuple, Dict, IO

if(TYPE_CHECKING):
from ..molecule import Chain
from ..molecule import Chain, Atom

def superimporse(reference: 'Chain', target: 'Chain', use: str='calpha', ids: List[int]=[], change_target: bool=True) -> Tuple[numpy.matrix, numpy.ndarray]:
"""This function is used to superimpose the Target Chain(coordinates will be changed) on the Reference Chain(coordinates will change).
Expand Down Expand Up @@ -172,21 +172,24 @@ def load_hinge(filename: str) -> Dict[str, List[float]]:
##################################################################################################
'''

def WriteOBJ(atoms, faces, fh):
def WriteOBJ(atoms: List['Atom'], faces: List['Atom'], fh: IO):
"""Write the .obj file to visualize the obtain alpha shape tesselations.
Note:
* One chain at a time.
Args:
atoms (packman.molecule.Atom): Atoms (Just for the node records)
faces ([float]) : SelectedTesselations (See the packman.apps.predict_hinge)
faces ([Atom]) : SelectedTesselations (See the packman.apps.predict_hinge)
fh (file) : Output file with .obj extension
"""
atoms = [i for i in atoms]
NewIDs = {i.get_id():numi+1 for numi,i in enumerate(atoms)}
fh.write('mtllib master.mtl\ng\n'.encode())
fh.write('usemtl atoms\n'.encode())
for i in atoms:
x, y, z = i.get_location()
fh.write("v %f %f %f\n".encode()%(x,y,z))
fh.write("v %f %f %f\n".encode()%(x, y, z))

line='usemtl bonds\nl'
for i in atoms:
Expand All @@ -196,8 +199,8 @@ def WriteOBJ(atoms, faces, fh):

fh.write('usemtl faces\n'.encode())
for i in faces:
faces = [NewIDs[j.get_id()] for j in i]
fh.write("f %i %i %i %i\n".encode()%(faces[0],faces[1],faces[2],faces[3]))
local_faces = [NewIDs[j.get_id()] for j in i]
fh.write("f %i %i %i %i\n".encode()%(local_faces[0], local_faces[1], local_faces[2], local_faces[3]))
#fh.write("l %i %i %i %i\n"%(faces[0],faces[1],faces[2],faces[3]))
return True

Expand Down

0 comments on commit 98d9067

Please sign in to comment.