diff --git a/modules/bindings/pymod/naccess.py b/modules/bindings/pymod/naccess.py index 5d9f20b6efb2e91c3367826070c96d1e7711f4d2..0d5566ea257d5ac69302cdcdd41ee0dc2feee088 100644 --- a/modules/bindings/pymod/naccess.py +++ b/modules/bindings/pymod/naccess.py @@ -109,15 +109,14 @@ def _ParseAsaFile(entity, file, asa_atom): chain_id = chain_id res_number = res_number.strip() asa = asa.strip() - #print "res_number:", res_number - m=re.match(r'(?P<num>-?\d+)(?P<ins>\w)?', res_number) + m = re.match(r'(?P<num>-?\d+)(?P<ins>\w)?', res_number) di = m.groupdict() if di["ins"] == None: resNum = mol.ResNum(int(di["num"])) else: resNum = mol.ResNum(int(di["num"]), di["ins"]) - #print res_number, resNum.num, resNum.ins + a = entity.FindAtom(chain_id, resNum, atom_name) if(a.IsValid()): a.SetFloatProp(asa_atom, float(asa)) @@ -125,7 +124,7 @@ def _ParseAsaFile(entity, file, asa_atom): LogWarning("NACCESS: invalid asa entry %s %s %s" \ % (chain_id, resNum, atom_name)) -def _ParseRsaFile(enti,file, asa_abs, asa_rel): +def _ParseRsaFile(entity, file, asa_abs, asa_rel): """ Reads Area file (.rsa) and attach asa (absolute + relative) per residue to an entitiy @@ -140,30 +139,25 @@ def _ParseRsaFile(enti,file, asa_abs, asa_rel): area_fh.close() # shift first line area_lines = area_lines[4:] - - + # parse lines for l in area_lines: if l.startswith("RES"): + # extract data p = re.compile(r'\s+') - t = p.split(l) - #res_name, chain_id , res_number, abs_all, rel_all = t[1:6] res_name = l[3:8] res_name = res_name.strip() chain_id = l[8:9] res_number = l[9:14] - res_number= res_number.strip() - #print l[15:30] - abs_all, rel_all =l[15:28].strip().split() - m=re.match(r'(?P<num>-?\d+)(?P<ins>\w)?', res_number) + res_number = res_number.strip() + abs_all, rel_all = l[15:28].strip().split() + m = re.match(r'(?P<num>-?\d+)(?P<ins>\w)?', res_number) di = m.groupdict() if di["ins"] == None: resNum = mol.ResNum(int(di["num"])) else: resNum = mol.ResNum(int(di["num"]), di["ins"]) - - res = enti.handle.FindResidue(chain_id, resNum) - #res = entity.FindResidue(chain_id, mol.ResNum(int(res_number))) - #print res_name, chain_id, res_number + # set res. props + res = entity.FindResidue(chain_id, resNum) if res_name == res.name: res.SetFloatProp(asa_rel, float(rel_all) ) res.SetFloatProp(asa_abs, float(abs_all) ) @@ -337,7 +331,7 @@ def CalculateSurfaceArea(entity, radius=1.4, __CleanupFiles(naccess_data_dir) # sum up Asa for all atoms - sasa = 0.0 + sasa = 0.0 for a in entity.atoms: sasa += a.GetFloatProp(asa_atom, 0.0) diff --git a/modules/bindings/tests/test_naccess.py b/modules/bindings/tests/test_naccess.py index 891f01bd75aa104edd0d8431fa5480f04250958b..c2b33b06315340b10eecca93c9adfab25cf37bb7 100644 --- a/modules/bindings/tests/test_naccess.py +++ b/modules/bindings/tests/test_naccess.py @@ -2,13 +2,12 @@ ''' import unittest -import os import sys import shutil import tempfile from ost.bindings import naccess -from ost import io +from ost import io, settings class TestNaccessBindings(unittest.TestCase): def testTempDirWithDot(self): @@ -18,13 +17,11 @@ class TestNaccessBindings(unittest.TestCase): def cleanup(): shutil.rmtree(na_tmp_dir) self.addCleanup(cleanup) - na_bin = os.path.join(os.getenv('EBROOTNACCESS'), 'naccess') ost_ent = io.LoadPDB('testfiles/testprotein.pdb') excp_raised = False try: sasa = naccess.CalculateSurfaceArea(ost_ent, - scratch_dir=na_tmp_dir, - naccess_exe=na_bin) + scratch_dir=na_tmp_dir) except: excp_raised = True raise @@ -33,10 +30,10 @@ class TestNaccessBindings(unittest.TestCase): "supposed to happen.") if __name__ == "__main__": - naccess_dir = os.getenv('EBROOTNACCESS') - if not naccess_dir: - print "No environment variable 'EBROOTNACCESS'. To enable the "+\ - "unit test, this needs to point to your Naccess installation." + try: + settings.Locate("naccess") + except: + print "Could not find NACCESS, could not test binding..." sys.exit(0) from ost import testutils testutils.RunTests()