molecupy.structures.atoms (Atoms)

This module contains classes for atoms and their bonds.

class molecupy.structures.atoms.GhostAtom(element, atom_id, atom_name)[source]

This class represents atoms with no location. It is a ‘ghost’ in the sense that it is accounted for in terms of its mass, but it is ‘not really there’ because it has no location and cannot form bonds.

The reason for the distinction between ghost atoms and ‘real’ atoms comes from PDB files, where often not all the atoms in the studied molecule can be located in the (for example) electron density data and so there are no coordinates for them. They do ‘exist’ but they are missing from the PDB file coordinates.

They are described in terms of an Atom ID, an Atom name, and an element. They have mass but no location, and they can still be associated with molecules and models.

Parameters:
  • element (str) – The atom’s element.
  • atom_id (int) – The atom’s id.
  • atom_name (str) – The atom’s name.
element(element=None)[source]

Returns or sets the atom’s element.

Parameters:element (str) – If given, the atom’s element will be set to this.
Return type:str
atom_id()[source]

Returns the atom’s ID.

Return type:int
atom_name(atom_name=None)[source]

Returns or sets the atom’s name.

Parameters:name (str) – If given, the atom’s name will be set to this.
Return type:str
mass()[source]

Returns the atom’s mass

Return type:float
molecule()[source]

Returns the SmallMolecule or Residue the atom is a part of.

model()[source]

Returns the Model the atom is a part of.

Return type:Model
class molecupy.structures.atoms.Atom(x, y, z, *args)[source]

Base class: GhostAtom

Represents standard atoms which have Cartesian coordinates, and which can form bonds with other atoms.

They are distinguished from GhostAtom objects because they have a location in three dimensional space, though they inherit some properties from that more generic class of atom.

Parameters:
  • x (float) – The atom’s x-coordinate.
  • y (float) – The atom’s y-coordinate.
  • z (float) – The atom’s z-coordinate.
  • element (str) – The atom’s element.
  • atom_id (int) – The atom’s id.
  • atom_name (str) – The atom’s name.
x(x=None)[source]

Returns or sets the atom’s x coordinate.

Parameters:x (float) – If given, the atom’s x coordinate will be set to this.
Return type:float
y(y=None)[source]

Returns or sets the atom’s y coordinate.

Parameters:y (float) – If given, the atom’s y coordinate will be set to this.
Return type:float
z(z=None)[source]

Returns or sets the atom’s z coordinate.

Parameters:z (float) – If given, the atom’s z coordinate will be set to this.
Return type:float
location()[source]

Returns the atom’s xyz coordinates as a tuple.

Return type:tuple
distance_to(other_atom)[source]

Returns the distance between this atom and another, in Angstroms. Alternatively, an AtomicStructure can be provided and the method will return the distance between this atom and that structure’s center of mass.

Parameters:other_atom – The other atom or atomic structure.
Return type:float
bonds()[source]

The set of Bond objects belonging to this atom.

Returns:set of Bond objects.
bond_to(other_atom)[source]

Creates a Bond between this atom and another.

Parameters:other_atom (Atom) – The other atom.
bonded_atoms()[source]

The set of Atom objects bonded to this atom.

Returns:set of Atom objects.
get_bond_with(other_atom)[source]

Returns the specific Bond between this atom and some other atom, if it exists.

Parameters:other_atom (Atom) – The other atom.
Return type:Bond
break_bond_with(other_atom)[source]

Removes the specific Bond between this atom and some other atom, if it exists.

Parameters:other_atom (Atom) – The other atom.
accessible_atoms(already_checked=None)[source]

The set of all Atom objects that can be accessed by following bonds.

Returns:set of Atom objects.
local_atoms(distance, include_hydrogens=True)[source]

Returns all Atom objects within a given distance of this atom (within a model).

Parameters:
  • distance – The cutoff in Angstroms to use.
  • include_hydrogens (bool) – determines whether to include hydrogen atoms.
Returns:

set of Atom objects.

class molecupy.structures.atoms.Bond(atom1, atom2)[source]

Represents a chemical bond between two Atom objects - covalent or ionic.

Parameters:
  • atom1 (Atom) – The first atom.
  • atom2 (Atom) – The second atom.
atoms()[source]

Returns the two atoms in this bond.

Returns:set of Atom
bond_length()[source]

The length of the bond in Angstroms.

Return type:float
delete()[source]

Removes the bond and updates the two atoms. Unless you have manually created some other reference, this will remove all references to the bond and it will eventually removed by garbage collection.