Linkage and Bonds

Represents the connections between residues, such as the bond between Substituent and Monosaccharide or the glycocidic bond between two Monosaccharide residues.

Bases: object

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

Attributes

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
__eq__(other)[source]

Performs deep equality testing between self and other

__getitem__(mol)

Alias for to()

__init__(parent, child, parent_position=-1, child_position=-1, parent_loss=None, child_loss=None, id=None, attach=True)[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: :class:`Monosaccharide` or :class:`Substituent`

child: :class:`Monosaccharide` or :class:`Substituent`

parent_position: int

The position on the parent to attach to Defaults to -1

child_position: int

The position on the child to attach to. Defaults to -1

parent_loss: :class:`Composition` or str

The elemental composition deducted from the parent when the bond is applied

child_loss: :class:`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, uuid4 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()

__iter__()[source]

Yields the parent node, then the child node

_glycoct_sigils(link)[source]

Helper method for determining which GlycoCT symbols and losses to present

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.

Sets _attached to True

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:

Monosaccharide or Substituent parent

Monosaccharide or Substituent child

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.

Returns: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.

Returns:bool
is_child(mol)[source]

Test mol for id() equality with child

Returns:bool
is_parent(mol)[source]

Test mol for id() equality with parent

Returns:bool

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

Returns:bool
reconnect(refund=False)[source]

The opposite of Link.break_link(), add self to the appropriate places on parent and child

Parameters:

refund: bool

Should Link.refund() be called? Defaults to False

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

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: :class:`Monosaccharide` or :class:`Substituent`

Returns:

Monosaccharide or Substituent

Raises:

KeyError:

If mol is not the parent or child of this 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

class glypy.structure.link.LinkMaskContext(residue, attach=False)[source]

Bases: object

A context manager for masking and unmasking Link objects on a residue

mask()[source]

For each Link captured, if that link is attched, call its break_link() method with refund=True

unmask()[source]

For each Link captured, if that link is not attched, call its apply() method