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

Represents the linkage between two molecules, described as an edge in a graph with optional directedness semantics.

Variables
  • parent (Monosaccharide or Substituent) –

  • child (Monosaccharide or Substituent) –

  • parent_position (int) – Position of link on parent

  • child_position (int) – position of link on child

  • parent_loss (Composition) – Elemental composition lost from the parent when forming this bond

  • child_loss (Composition) – Elemental composition lost from the child 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 see is_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 and child 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 unless attach=False. If not attached on instantiation, the bond can be realized by calling Link.apply() at a later time.

Parameters
  • parent (Monosaccharide or Substituent) –

  • child (Monosaccharide or Substituent) –

  • 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 applied

  • child_loss (Composition or str) – The elemental composition deducted from the child when the bond is applied

  • id (int) – A locally unique identifier within a graph. If None, uid() is used to generate one. Defaults to None

  • attach (bool) – Whether to immediately attach the Link object to the parent and child molecules on instantiation by using Link.apply()

Connection State Management

Link.apply()[source]

Actually alter parent and child’s state. Deduct their respective losses from their composition and insert a reference to self into their links or substituent_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 to True

See also

Link.break_link(), Link.refund(), Monosaccharide.is_occupied()

This function reverses Link.apply(), removing the reference to self from both parent and child’s store of links. If refund is True, Link.refund() will be called, restoring the lost elemental composition from this bond.

Sets _attached to False

Returns

Allow Failure

Link.try_apply()[source]

Try to apply the link if it is not attached, otherwise return False

Try to break the link if it is attached, otherwise return False

Helpers

Link.refund()[source]

Returns the lost elemental composition caused by apply(). Adds back parent_loss and child_loss to the composition of parent and child respectively

Traversal

Link.to(mol)[source]

Traverse the link from mol to its adjacent node. If mol is not self.parent or self.child, instead raises an error. __getitem__() is an alias of to

Parameters

mol (Monosaccharide or Substituent) –

Return type

Monosaccharide or Substituent

Raises

KeyError – If mol is not the parent or child of this Link

Link.__iter__()[source]

Yields the parent node, then the child node

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_parent(mol)[source]

Test mol for id() equality with parent

Return type

bool

Link.is_child(mol)[source]

Test mol for id() equality with child

Return type

bool

Link.is_attached(deep=False)[source]

Test to see if self is present in parent and child link structures. Presences indicates the link is attached.

Return type

bool

If child is a Substituent and parent is a Monosaccharide, then self is a substituent_link

Return type

bool

If parent is a Substituent and child is a Monosaccharide, then self is a bridge_link

Return type

bool

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

bool

Link.has_ambiguous_linkage()[source]

Returns whether the link position at either terminal is ambiguous, but not unknown.

Return type

bool

Link.has_ambiguous_termini()[source]

Returns whether the link terminal is ambiguous

Return type

bool

Utilities

Link.clone(parent, child, prop_id=True, attach=True)[source]

Given two new objects parent and child, duplicate all other information in self, creating a new Link object between parent and child with the same properties as self.

Return type

Link

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()

Link.__eq__(other)[source]

Performs deep equality testing between self and other

Link.trait_equality(other)[source]

Test whether the intrinsic attributes of another Link object match this link without examining the actual termini.

Parameters

other (Link) – The object to compare against

Return type

bool

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.

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.

Variables
  • parent_choices (list) – The set of possible choices for parent

  • parent_position_choices (list) – The set of possible choices for parent_position

  • child_choices (list) – The set of possible choices for child

  • child_position_choices (list) – The set of possible choices for child_position

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 calls apply().

Parameters
  • parent (Monosaccharide or Substituent) – The parent of the link to form

  • child (Monosaccharide or :class:`~.Substituent) – The child of the link to form

  • parent_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 is True, call reconfigure() with each specification.

Parameters

attach (bool, optional) – Whether or not to apply each configuration. The default is False

Yields

tuple of parent, child, parent_position, child_position

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.