6 This module is for structural alignment from OpenStructure using the external program 3DCOMB.
8 How To Use This Module:
9 1. Import it (e.g. as "from ost.bindings import align_3dcomb")
10 2. Use it (e.g. as "alignment,transformation_list = align_3dcomb.AlignStructures(view_list)")
18 from ost
import settings
23 def _GetExecutable(comb_exe, comb_env):
25 Function to check if 3DCOMB executable is present
27 :param comb_exe: Explicit path to 3DCOMB executable
28 :param msms_env: Environment variable pointing to 3DCOMB executable
29 :returns: Path to the executable
30 :raises: :class:`~ost.FileNotFound` if executable is not found
32 return settings.Locate([
'3DCOMB_linux',
'3DCOMB_win.exe'], explicit_file_name=comb_exe,
35 def _SetupFiles(structure_list):
37 Setup files for MSMS calculation in temporary directory
39 :param structure_list: A list of EntityView that will be aligned.\
40 each EntityView should contain a single chain and each residue needs to have a CA atom.
41 :returns: calss:settings.TempDir
42 :raises: class:`RuntimeError` if on of the Views is not valid
46 if not all([ev.IsValid()
for ev
in structure_list]):
47 raise RuntimeError,
"Invalid EntityView in structure_list"
51 outfile=open(os.path.join(tpd.dirname,
'list'),
'w')
52 outfile.write(
'\n'.join(tpd.files))
57 def _Run3DCOMB(command,tpd):
59 Run the 3DCOMB alignment command
61 This functions starts the external 3DCOMB executable and returns the stdout of
64 :param command: Command to execute
65 :returns: stdout of 3DCOMB
66 :raises: :class:`CalledProcessError` for non-zero return value
68 outname=os.path.join(tpd.dirname,
'align.out')
69 outfile=open(outname,
'w')
70 returncode=subprocess.call(command, shell=
True, stdout=outfile)
74 print "WARNING: 3DCOMB error\n"
75 raise subprocess.CalledProcessError
78 def _ParseOutput(tpd):
80 ali=io.LoadAlignment(os.path.join(tpd.dirname,
'list.ali'),
'fasta')
81 for i
in range(ali.GetCount()):
82 ali.SetSequenceName(i,
'struc{0}'.format(i))
84 f=open(os.path.join(tpd.dirname,
'list.rmt'),
'r')
92 fl.extend([float(el)
for el
in sl[0].split()+[sl[1]]])
94 T=ost.geom.Transform()
99 outfile=open(os.path.join(tpd.dirname,
'align.out'),
'r')
102 if line.startswith(
'Objective function value is'):results[
'objective_function']=float(line.split()[-1])
103 if line.startswith(
'CORE_LEN'):
107 results[s[0]]=float(s[1])
108 return ali,Tl,results
111 def AlignStructures(structure_list,apply_transform=False,name_list=None,comb_exe=None,comb_env=None):
112 comb_executable=_GetExecutable(comb_exe, comb_env)
113 tpd=_SetupFiles(structure_list)
114 command=
' '.join([comb_executable,os.path.join(tpd.dirname,
'list')])
115 returncode=_Run3DCOMB(command,tpd)
116 try:ali,Tl,results=_ParseOutput(tpd)
118 print 'could not parse output'
121 for T,ev
in zip(Tl,structure_list):
122 ev.handle.FixTransform()
123 ev.handle.SetTransform(T)
125 return ali,Tl,results