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 (
Monosaccharide
orSubstituent
) –child (
Monosaccharide
orSubstituent
) –parent_position (int) – Position of link on
parent
child_position (int) – position of link on
child
parent_loss (
Composition
) – Elemental composition lost from theparent
when forming this bondchild_loss (
Composition
) – Elemental composition lost from thechild
when 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
parent
andchild
between the molecule positions specified. The bond may represent a partial loss of elemental composition from the parent and/or child molecules.Instantiating the
Link
object 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 (
Monosaccharide
orSubstituent
) –child (
Monosaccharide
orSubstituent
) –parent_position (int) – The position on the parent to attach to Defaults to
UnknownPosition
child_position (int) – The position on the child to attach to. Defaults to
UnknownPosition
parent_loss (
Composition
or str) – The elemental composition deducted from the parent when the bond is appliedchild_loss (
Composition
or 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 toNone
attach (bool) – Whether to immediately attach the
Link
object to theparent
andchild
molecules on instantiation by usingLink.apply()
Connection State Management¶
- Link.apply()[source]¶
Actually alter
parent
andchild
’s state. Deduct their respective losses from theircomposition
and insert a reference toself
into theirlinks
orsubstituent_links
as 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
_attached
toTrue
See also
Link.break_link()
,Link.refund()
,Monosaccharide.is_occupied()
- Link.break_link(refund=False)[source]¶
This function reverses
Link.apply()
, removing the reference toself
from bothparent
andchild
’s store of links. Ifrefund
isTrue
,Link.refund()
will be called, restoring the lost elemental composition from this bond.Sets
_attached
toFalse
- Returns
Monosaccharide
orSubstituent
parentMonosaccharide
orSubstituent
child
Allow Failure¶
Helpers¶
Traversal¶
- Link.to(mol)[source]¶
Traverse the link from
mol
to its adjacent node. Ifmol
is notself.parent
orself.child
, instead raises an error.__getitem__()
is an alias ofto
- Parameters
mol (
Monosaccharide
orSubstituent
) –- 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
self
is present inparent
andchild
link structures. Presences indicates the link is attached.- Return type
- Link.is_substituent_link()[source]¶
If
child
is aSubstituent
andparent
is aMonosaccharide
, thenself
is a substituent_link- Return type
- Link.is_bridge_link()[source]¶
If
parent
is aSubstituent
andchild
is aMonosaccharide
, thenself
is 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
parent
andchild
, duplicate all other information inself
, creating a newLink
object betweenparent
andchild
with 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
Link
that 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 (
Monosaccharide
orSubstituent
) – The parent of the link to formchild (
Monosaccharide
or :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
attach
isTrue
, 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.