20 Wrapper for the CAD score.
24 Olechnovic K, Kulberkyte E, Venclovas C., CAD-score: A new contact area
25 difference-based function for evaluation of protein structural models
26 Proteins. 2012 Aug 30. [Epub ahead of print]
28 Authors: Valerio Mariani, Alessandro Barbato
31 import subprocess, os, tempfile, platform
32 from ost
import settings, io
34 def _SetupFiles(model,reference):
36 tmp_dir_name=tempfile.mkdtemp()
38 for chain
in model.chains:
40 raise RuntimeError(
"One of the chains in the model has no name. Cannot calculate CAD score")
41 if len(chain.name) > 1:
44 for res
in chain.residues:
48 io.SavePDB(model, os.path.join(tmp_dir_name,
'model.pdb'), dialect=dia)
50 for chain
in reference.chains:
52 raise RuntimeError(
"One of the chains in the reference has no name. Cannot calculate CAD score")
53 if len(chain.name) > 1:
56 for res
in chain.residues:
60 io.SavePDB(reference, os.path.join(tmp_dir_name,
'reference.pdb'),dialect=dia)
63 def _CleanupFiles(dir_name):
65 shutil.rmtree(dir_name)
70 Holds the result of running CAD
72 .. attribute:: globalAA
74 The global CAD's atom-atom (AA) score
76 .. attribute:: localAA
78 Dictionary containing local CAD's atom-atom (AA) scores.
80 :type: dictionary (key: chain.resnum (e.g.: A.24), value: CAD local AA score (see CAD Documentation online)
86 def _ParseCADGlobal(lines):
87 interesting_lines=lines[1]
88 aa=float(interesting_lines.split()[10])
91 def _ParseCADLocal(lines):
93 for lin
in lines[11:]:
97 key=chain+
'.'+str(resnum)
102 def _RunCAD(max_iter, tmp_dir):
103 model_filename=os.path.join(tmp_dir,
'model.pdb')
104 reference_filename=os.path.join(tmp_dir,
'reference.pdb')
105 if platform.system() ==
"Windows":
106 raise RuntimeError(
'CAD score not available on Windows')
108 cad_calc_path=settings.Locate(
'CADscore_calc.bash')
109 cad_read_g_path=settings.Locate(
'CADscore_read_global_scores.bash')
110 cad_read_l_path=settings.Locate(
'CADscore_read_local_scores.bash')
111 command1=
"\"%s\" -o %i -m \"%s\" -t \"%s\" -D \"%s\"" %(cad_calc_path, max_iter, model_filename, reference_filename, os.path.join(tmp_dir,
"cadtemp"))
112 command2=
"\"%s\" -D \"%s\"" %(cad_read_g_path, os.path.join(tmp_dir,
"cadtemp"))
113 command3=
"\"%s\" -m \"%s\" -t \"%s\" -D \"%s\" -c AA" %(cad_read_l_path, model_filename, reference_filename,os.path.join(tmp_dir,
"cadtemp"))
114 ps1=subprocess.Popen(command1, shell=
True, stdout=subprocess.PIPE)
116 ps2=subprocess.Popen(command2, shell=
True, stdout=subprocess.PIPE)
118 lines=ps2.stdout.readlines()
120 globalAA=_ParseCADGlobal(lines)
122 raise RuntimeError(
"CAD calculation failed")
123 ps3=subprocess.Popen(command3, shell=
True, stdout=subprocess.PIPE)
125 lines=ps3.stdout.readlines()
127 localAA=_ParseCADLocal(lines)
129 raise RuntimeError(
"CAD calculation failed")
136 Calculates global and local atom-atom (AA) CAD Scores
139 :param model: The model structure.
140 :type model: :class:`~ost.mol.EntityView` or :class:`~ost.mol.EntityHandle`
141 :param reference: The reference structure
142 :type model2: :class:`~ost.mol.EntityView` or :class:`~ost.mol.EntityHandle`
143 :param max_iter: Optional. The maximum number of iteration for the tessellation algorithm before giving up. By default 300
144 :returns: The result of the CAD score calculation
145 :rtype: :class:`CADResult`
147 :raises: :class:`~ost.settings.FileNotFound` if any of the CAD score exacutables could not be located.
148 :raises: :class:`RuntimeError` if the calculation failed
150 tmp_dir_name=_SetupFiles(model, reference)
151 result=_RunCAD(max_iter, tmp_dir_name)
152 _CleanupFiles(tmp_dir_name)