Source code for schrodinger.structutils.structalign
"""
A module for performing protein structure alignment. This requires Prime to
be installed and licensed appropriately as the SKA program distributed
with Prime is what is actually used to do the alignment.
The structural alignment is performed and the results are added as properties
to the input CTs. For each template the alignment is returned along with
the raw output from ska.
Copyright Schrodinger, LLC. All rights reserved.
"""
# Contributors: Quentin McDonald, Matvey Adzhigirey, John Gunn
from schrodinger.utils import log
logger = log.get_logger()
# Check whether SCHRODINGER_PYTHON_DEBUG is set for debugging:
DEBUG = (log.get_environ_log_level() <= log.DEBUG)
[docs]class StructAlign(object):
"""
This is the class used to perform the structural alignment. This class
will check at initialization time if Prime is installed by trying to
import schrodinger.applications.ska and will fail if it's not installed
as nothing more can be done.
There are a number of properties that can be set for instances of this
class which are used to control how the alignment is done:
gap_penalty - default = 2.0
deletion_penalty = default = 1.0
use_scanning_alignment - default = False
window_length - default = 5
minimum_similarity - default = 1.0
minimum_length - default = 2
use_automatic_settings - default = False
use_standard_residues - default = False
reorder_by_connectivity - default = False
"""
[docs] def __init__(self):
"""
Construct an instance of a StructAlign object. This method will
check that schrodinger.application.ska is available and fail with
a RuntimeError if it's not
"""
try:
from schrodinger.application import ska
except:
raise RuntimeError("Prime is not installed, it is " +\
"required to instantiate this class")
self.pairwise_align_ct = ska.pairwise_align_ct
# Initialize the variables:
self._ref_st = None
self._gap_penalty = 2.0
self._deletion_penalty = 1.0
self._use_scanning_alignment = False
self._window_length = 5
self._minimum_similarity = 1.0
self._minimum_length = 2.0
self.use_automatic_settings = False
self.use_standard_residues = False
self.reorder_by_connectivity = False
return
# gap_penalty: property for controlling the gap penalty:
def _setGapPenalty(self, penalty):
self._gap_pentalty = penalty
return
def _getGapPenalty(self):
return self._gap_penalty
gap_penalty = property(_getGapPenalty,
_setGapPenalty,
doc="Access to the gap penalty for the alignment")
# deletion_penalty: property for controlling the deletion penalty
def _setDeletionPenalty(self, penalty):
self._deletion_penalty = penalty
return
def _getDeletionPenalty(self):
return self._deletion_penalty
deletion_penalty = property(
_getDeletionPenalty,
_setDeletionPenalty,
doc="Access to the deletion penalty for the alignment")
# Use scanning aligment flag
def _setUseScanningAlignment(self, scanning_alignment):
self._use_scanning_alignment = scanning_alignment
return
def _getUseScanningAlignment(self):
return self._use_scanning_alignment
use_scanning_alignment = property(
_getUseScanningAlignment,
_setUseScanningAlignment,
doc="Access to the use scanning alignment flag")
# Window length property:
def _setWindowLength(self, length):
self._window_length = length
return
def _getWindowLength(self):
return self._window_length
window_length = property(_getWindowLength,
_setWindowLength,
doc="Access to the window length for the aligment")
# Minimum similarity property:
def _setMinimumSimilarity(self, min_sim):
self._minimum_similarity = min_sim
return
def _getMinimumSimilarity(self):
return self._minimum_similarity
minimum_similarity = property(
_getMinimumSimilarity,
_setMinimumSimilarity,
doc="Access to the minimum similarity used in the alignment")
# Minimum Length property
def _setMinimumLength(self, min_length):
self._minimum_length = min_length
return
def _getMinimumLength(self):
return self._minimum_length
minimum_length = property(
_getMinimumLength,
_setMinimumLength,
doc="Access to the minimum length used in the alignment")
[docs] def align(self, ref_st, sts):
"""
Perform a structural alignment on the Structure objects in the
list 'sts' relative to the reference structure 'ref_st'
Each structure in the list is aligned relative to the reference
structure. The coordinates of the input structures are modified to
give the best structural alignment.
"""
cmdopts = {
'MODE': 'align',
'ORDER': 'seed',
'GAP_OPEN': self._gap_penalty,
'GAP_DEL': self._deletion_penalty,
'SSE_MINSIM': self._minimum_similarity,
'SSE_MINLEN': self._minimum_length
}
if self._use_scanning_alignment:
cmdopts['SSE_WINLEN'] = self._window_length
if self.use_automatic_settings:
cmdopts['USE_AUTOMATIC_SETTINGS'] = 'yes'
std_res = self.use_standard_residues
reorder = self.reorder_by_connectivity
output = self.pairwise_align_ct(query=('ref', ref_st),
templist=[('sup', st) for st in sts],
keywords=cmdopts,
log=logger,
debug=DEBUG,
save_props=True,
std_res=std_res,
reorder=reorder)
return [(out.align, out.stdout) for out in output]
[docs] def alignStructure(self, ref_st, mob_st):
"""
Perform a structural alignment on the mob_st structure relative to the
ref_st structure. The coordinates of the input mob_st structure are
modified to give the best structural alignment.
"""
return self.align(ref_st, [mob_st])[0]
#EOF