Linkage and Bonds¶
Represents the connections between residues, such as the bond between Substituent and Monosaccharide or the glycocidic bond between two Monosaccharide residues.
Explicit Linkages¶
- class glypy.structure.link.Link(parent, child, parent_position=-1, child_position=-1, parent_loss=None, child_loss=None, id=None, attach=True, parent_linkage_type=None, child_linkage_type=None)[source]¶
Represents the linkage between two molecules, described as an edge in a graph with optional directedness semantics.
- Variables:
parent (
MonosaccharideorSubstituent)child (
MonosaccharideorSubstituent)parent_position (int) – Position of link on
parentchild_position (int) – position of link on
childparent_loss (
Composition) – Elemental composition lost from theparentwhen forming this bondchild_loss (
Composition) – Elemental composition lost from thechildwhen forming this bond_attached (
bool) – An internal flag that keeps track of whether or not a link is attached to its termini. Should not be read or manipulated directly. Instead seeis_attached().
- Link.__init__(parent, child, parent_position=-1, child_position=-1, parent_loss=None, child_loss=None, id=None, attach=True, parent_linkage_type=None, child_linkage_type=None)[source]¶
Defines a bond between
parentandchildbetween the molecule positions specified. The bond may represent a partial loss of elemental composition from the parent and/or child molecules.Instantiating the
Linkobject will automatically attach it to its endpoints, mutating them unlessattach=False. If not attached on instantiation, the bond can be realized by callingLink.apply()at a later time.- Parameters:
parent (
MonosaccharideorSubstituent)child (
MonosaccharideorSubstituent)parent_position (int) – The position on the parent to attach to Defaults to
UnknownPositionchild_position (int) – The position on the child to attach to. Defaults to
UnknownPositionparent_loss (
Compositionor str) – The elemental composition deducted from the parent when the bond is appliedchild_loss (
Compositionor str) – The elemental composition deducted from the child when the bond is appliedid (int) – A locally unique identifier within a graph. If
None,uid()is used to generate one. Defaults toNoneattach (bool) – Whether to immediately attach the
Linkobject to theparentandchildmolecules on instantiation by usingLink.apply()
Connection State Management¶
- Link.apply()[source]¶
Actually alter
parentandchild’s state. Deduct their respective losses from theircompositionand insert a reference toselfinto theirlinksorsubstituent_linksas appropriate.This performs no position availability validation. If there is a possibility that either the parent or child position may be occupied, they should be tested using
is_occupied()prior to calling this method.Sets
_attachedtoTrueSee also
Link.break_link(),Link.refund(),Monosaccharide.is_occupied()
- Link.break_link(refund=False)[source]¶
This function reverses
Link.apply(), removing the reference toselffrom bothparentandchild’s store of links. IfrefundisTrue,Link.refund()will be called, restoring the lost elemental composition from this bond.Sets
_attachedtoFalse- Returns:
MonosaccharideorSubstituentparentMonosaccharideorSubstituentchild
Allow Failure¶
Helpers¶
Traversal¶
- Link.to(mol)[source]¶
Traverse the link from
molto its adjacent node. Ifmolis notself.parentorself.child, instead raises an error.__getitem__()is an alias ofto- Parameters:
mol (
MonosaccharideorSubstituent)- Return type:
- Raises:
Connection Testing¶
These methods help determine if some object is related to a Link instance, or
can classify the type of linkage represented.
- Link.is_attached(deep=False)[source]¶
Test to see if
selfis present inparentandchildlink structures. Presences indicates the link is attached.- Return type:
- Link.is_substituent_link()[source]¶
If
childis aSubstituentandparentis aMonosaccharide, thenselfis a substituent_link- Return type:
- Link.is_bridge_link()[source]¶
If
parentis aSubstituentandchildis aMonosaccharide, thenselfis a bridge_link- Return type:
Ambiguity Testing¶
These methods are useful for switching behaviors when linkage is ambiguous. The base Link class
provides dummy implementations of these methods, but the AmbiguousLink subclass implements them.
- Link.is_ambiguous()[source]¶
Returns if the link position or link terminal at either end is ambiguous, but not unknown.
- Return type:
Utilities¶
- Link.clone(parent, child, prop_id=True, attach=True)[source]¶
Given two new objects
parentandchild, duplicate all other information inself, creating a newLinkobject betweenparentandchildwith the same properties asself.- Return type:
Link objects support equality comparison, but this tests the equality of their termini. To test
whether two links’ other properties are equal, see, Link.trait_equality()
Ambiguous Linkages with Multiple Positions or Terminals¶
Sometimes a link may be ambiguous, with several options for connection positions,
or terminal residues. When representing these cases, glypy uses an AmbiguousLink
instead of a regular Link. They inherit all the behaviors of Link, but
add several new fields for storing the possible options for each attribute, and provide
means for switching amongst different configurations.
- class glypy.structure.link.AmbiguousLink(parent, child, parent_position=(-1,), child_position=(-1,), parent_loss=None, child_loss=None, id=None, attach=True, parent_linkage_type=None, child_linkage_type=None)[source]¶
A
Linkthat may have more than one option for connection position at either terminal, or the terminals themselves may be chosen from a set of options.
Configuration Combinations¶
- AmbiguousLink.reconfigure(parent, child, parent_position, child_position)[source]¶
Apply the specified configuration, replacing the current configuration.
This method calls
break_link()to refund the current bonds and then callsapply().- Parameters:
parent (
MonosaccharideorSubstituent) – The parent of the link to formchild (
Monosaccharideor :class:`~.Substituent) – The child of the link to formparent_position (int) – The position on the parent to connect to
child_position (int) – The position on the child to connect to
- AmbiguousLink.iterconfiguration(attach=False)[source]¶
Iterate over possible configurations for this link, yielding them.
If
attachisTrue, callreconfigure()with each specification.
- AmbiguousLink.find_open_position(attach=True)[source]¶
Identify a valid configuration of parent, child and respective positions which are all open.
- Parameters:
attach (bool, optional) – Whether or not to actually connect to the selected configuration, which will break the current configuration (the default is
True).- Raises:
ValueError: – When no valid configuration can be found.