Source code for ccpn.core.Atom

"""
"""
#=========================================================================================
# Licence, Reference and Credits
#=========================================================================================
__copyright__ = "Copyright (C) CCPN project (www.ccpn.ac.uk) 2014 - $Date: 2016-08-05 11:02:08 +0100 (Fri, 05 Aug 2016) $"
__credits__ = "Wayne Boucher, Rasmus H Fogh, Simon P Skinner, Geerten W Vuister"
__license__ = ("CCPN license. See www.ccpn.ac.uk/license"
              "or ccpnmodel.ccpncore.memops.Credits.CcpnLicense for license text")
__reference__ = ("For publications, please use reference from www.ccpn.ac.uk/license"
                " or ccpnmodel.ccpncore.memops.Credits.CcpNmrReference")

#=========================================================================================
# Last code modification:
#=========================================================================================
__author__ = "$Author: rhfogh $"
__date__ = "$Date: 2016-08-05 11:02:08 +0100 (Fri, 05 Aug 2016) $"
__version__ = "$Revision: 9763 $"

#=========================================================================================
# Start of code
#=========================================================================================

import typing

from ccpn.core.Residue import Residue
from ccpn.core._implementation.AbstractWrapperObject import AbstractWrapperObject
from ccpn.core.lib import Pid
from ccpn.core.lib.Util import AtomIdTuple
from ccpnmodel.ccpncore.api.ccp.molecule.MolSystem import Atom as ApiAtom

[docs]class Atom(AbstractWrapperObject): """A molecular Atom, contained in a Residue.""" #: Class name and Short class name, for PID. shortClassName = 'MA' # Attribute it necessary as subclasses must use superclass className className = 'Atom' _parentClass = Residue #: Name of plural link to instances of class _pluralLinkName = 'atoms' #: List of child classes. _childClasses = [] # Qualified name of matching API class _apiClassQualifiedName = ApiAtom._metaclass.qualifiedName() # CCPN properties @property def _apiAtom(self) -> ApiAtom: """ CCPN atom matching Atom""" return self._wrappedData @property def _parent(self) -> Residue: """Residue containing Atom.""" return self._project._data2Obj[self._wrappedData.residue] residue = _parent @property def _key(self) -> str: """Atom name string (e.g. 'HA') regularised as used for ID""" return self._wrappedData.name.translate(Pid.remapSeparators) @property def _idTuple(self) -> AtomIdTuple: """ID as chainCode, sequenceCode, residueType, atomName namedtuple NB Unlike the _id and key, these do NOT have reserved characters mapped to '^' NB _idTuple replaces empty strings with None""" parent = self._parent ll = [parent._parent.shortName, parent.sequenceCode, parent.residueType, self.name] return AtomIdTuple(*(x or None for x in ll)) @property def name(self) -> str: """Atom name string (e.g. 'HA')""" return self._wrappedData.name @property def boundAtoms(self) -> typing.Tuple['Atom']: """Atoms that are covalently bound to this Atom""" getDataObj = self._project._data2Obj.get apiAtom = self._wrappedData boundApiAtoms = list(apiAtom.boundAtoms) for apiBond in apiAtom.genericBonds: ll = list(apiBond.atoms) apiAtom2 = ll[0] if apiAtom is ll[1] else ll[1] boundApiAtoms.append(apiAtom2) boundAtoms = (getDataObj(x) for x in boundApiAtoms) return tuple(sorted(x for x in boundAtoms if x is not None))
[docs] def addInterAtomBond(self, atom:'Atom'): """ADVANCED Add generic bond between atoms - for creating disulfides or other crosslinks The bound-to atom will appear in self.boundAtoms. NB This function does not remove superfluous atoms (like CYS HG), or check for chemical plausibility. Programmer beware!""" project = self._project project._wrappedData.molSystem.newGenericBond(atoms=(self._wrappedData, atom._wrappedData))
# Utility functions # Implementation functions @classmethod def _getAllWrappedData(cls, parent: Residue)-> list: """get wrappedData (MolSystem.Atoms) for all Atom children of parent Residue""" return parent._wrappedData.sortedAtoms()
# No 'new' function - chains are made elsewhere # Connections to parents: # Notifiers: