Source code for schrodinger.protein.properties

import csv
import os

from schrodinger import structure
from schrodinger.models import json
from schrodinger.models import jsonable
from schrodinger.models import parameters
from schrodinger.utils import csv_unicode
from schrodinger.utils import qt_utils

#===============================================================================
# Properties/Descriptors
#===============================================================================

PropertySource = jsonable.JsonableEnum("PropertySource",
                                       ["Residue", "Sequence", "Structure"])
PropertyType = jsonable.JsonableEnum("PropertyType",
                                     ["Descriptor", "StructureProperty"])

ALL_SEQ_DESCRIPTORS_FPATH = os.path.join(os.path.dirname(__file__),
                                         'all_seq_descriptors.csv')


[docs]def get_prop_name_to_display_name_map(): with csv_unicode.reader_open(ALL_SEQ_DESCRIPTORS_FPATH) as infile: reader = csv.DictReader(infile) prop_name_to_display_name_map = dict() for row in reader: try: property_name = row['DESCRIPTOR'] display_name = row['DISPLAY_NAME'] prop_name_to_display_name_map[property_name] = display_name except KeyError: pass return prop_name_to_display_name_map
prop_name_to_display_name_map = get_prop_name_to_display_name_map()
[docs]@qt_utils.add_enums_as_attributes(PropertySource) @qt_utils.add_enums_as_attributes(PropertyType) class SequenceProperty(parameters.CompoundParam): visible: bool property_name: str property_source: PropertySource # Residue, Sequence, or Structure property_type: PropertyType # Descriptor or StructureProperty description: str = None display_name: str = None
[docs] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._setDefaultDisplayName()
def _setDefaultDisplayName(self): if not self.display_name: if self.property_type == self.StructureProperty: self.display_name = structure.PropertyName( self.property_name).userName() else: self.display_name = prop_name_to_display_name_map.get( self.property_name, self.property_name)
[docs] @json.adapter(version=50002) def adapter_50002(self, json_dict): """ In 50002 we split the property_source param into two separate property_type and property_source params """ old_prop_source = json_dict.pop("property_source") if old_prop_source == 4: # Old Structure Property prop_type = PropertyType.StructureProperty.toJsonImplementation() prop_source = PropertySource.Sequence.toJsonImplementation() else: prop_type = PropertyType.Descriptor.toJsonImplementation() prop_source = old_prop_source json_dict["property_source"] = prop_source json_dict["property_type"] = prop_type return json_dict
[docs]def get_CA_atom_props(aln): """ Get the CA atom properties of each structured residues in the alignment. :param aln: The alignment to use. :type aln: schrodinger.protein.alignment.BaseAlignment :return: list of sequence property object. :rtype: List[properties.SequenceProperty] """ atom_props = [] structured_residues = aln.getResiduesWithStructure() for res in structured_residues: for prop_name in res.getStructureResProperties(): if prop_name[0] not in (structure.PROP_FLOAT, structure.PROP_INTEGER): continue atom_prop = SequenceProperty( property_name=prop_name, property_type=PropertyType.StructureProperty, property_source=PropertySource.Structure) if atom_prop not in atom_props: atom_props.append(atom_prop) return atom_props