Molecule#

class pyjess.Atom#

A single atom in a molecule.

Added in version 0.4.0: Equality, hashing and pickle protocol support.

__init__(*, serial, name, altloc, residue_name, chain_id, residue_number, insertion_code, x, y, z, occupancy=0.0, temperature_factor=0.0, segment='', element='', charge=0)#

Create a new atom.

Raises:
  • MemoryError – When the system allocator fails to allocate enough memory for the atom storage.

  • ValueError – When either of the name, residue_name, segment, element or chain_id strings is too long.

copy()#

Create a copy of this atom.

Returns:

Atom – A newly allocated atom with identical attributes.

Added in version 0.4.0.

classmethod load(file)#

Load an atom from the given file.

Parameters:

file (file-like object) – A file-like object opened in text mode to read the atom from.

classmethod loads(text)#

Load an atom from the given string.

Parameters:

text (str, bytes or bytearray) – The atom line to read the atom metadata from.

altloc#

The alternate location indicator for the atom.

Type:

str

chain_id#

The identifier of the chain the atom belongs to.

Type:

str

charge#

The atom charge.

Type:

int

element#

The element symbol.

Type:

str

insertion_code#

The code for insertion of residues.

Type:

str

name#

The atom name.

Type:

str

occupancy#

The atom occupancy.

Type:

float

residue_name#

The residue name.

Type:

str

residue_number#

The residue sequence number.

Type:

int

segment#

The segment identifier.

Type:

str

serial#

The atom serial number.

Type:

int

temperature_factor#

The atom temperature factor.

Type:

float

class pyjess.Molecule#

A molecule structure, as a sequence of Atom objects.

Added in version 0.2.2: Support identifiers of arbitrary length.

Added in version 0.4.0: Equality, hashing and pickle protocol support.

__getitem__(key, /)#

Return self[key].

__init__(atoms=(), id=None)#

Create a new molecule.

Parameters:
  • atoms (sequence of Atom) – The atoms of the molecule.

  • id (str, optional) – The identifier of the molecule.

Raises:

MemoryError – When the system allocator fails to allocate enough memory for the molecule storage.

__len__()#

Return len(self).

copy()#

Create a copy of this molecule and its atoms.

Returns:

Molecule – A newly allocated molecule with the same identifier and atoms.

Added in version 0.4.0.

classmethod load(file, id=None, ignore_endmdl=False)#

Load a molecule from a PDB file.

Parameters:
  • file (str, os.PathLike, or file-like object) – Either the path to a file, or a file-like object opened in text mode containing a PDB molecule.

  • id (str, optional) – The identifier of the molecule. If None given, the parser will attempt to extract it from the HEADER line.

  • ignore_endmdl (bool) – Pass True to make the parser read all the atoms from the PDB file. By default, the parser only reads the atoms of the first model, and stops at the first ENDMDL line.

Returns:

Molecule – The molecule parsed from the PDB file.

classmethod loads(text, id=None, ignore_endmdl=False)#

Load a molecule from a PDB string.

Parameters:
  • file (str, os.PathLike, or file-like object) – Either the path to a file, or a file-like object opened in text mode containing a PDB molecule.

  • id (str, optional) – The identifier of the molecule. If None given, the parser will attempt to extract it from the HEADER line.

  • ignore_endmdl (bool) – Pass True to make the parser read all the atoms from the PDB file. By default, the parser only reads the atoms of the first model, and stops at the first ENDMDL line.

Returns:

Molecule – The molecule parsed from the PDB file.

See also

Molecule.load to load a PDB molecule from a file-like object or from a path.