vermouth.pdb.pdb module

Provides functions for reading and writing PDB files.

class vermouth.pdb.pdb.PDBParser(exclude=('SOL',), ignh=False, modelidx=1)[source]

Bases: LineParser

Parser for PDB files

active_molecule

The molecule/model currently being read.

Type:

vermouth.molecule.Molecule

molecules

All complete molecules read so far.

Type:

list[vermouth.molecule.Molecule]

modelidx

Which model to take.

Type:

int

Parameters:
  • exclude (collections.abc.Container[str]) – Container of residue names. Any atom that has a residue name that is in exclude will be skipped.

  • ignh (bool) – Whether all hydrogen atoms should be skipped

  • modelidx (int) – Which model to take.

static anisou(line, lineno=0)

Does nothing.

atom(line, lineno=0)

Parse an ATOM or HETATM record.

Parameters:
  • line (str) – The line to parse. We do not check whether it starts with either “ATOM “ or “HETATM”.

  • lineno (int) – The line number (not used).

static author(line, lineno=0)

Does nothing.

static caveat(line, lineno=0)

Does nothing.

static cispep(line, lineno=0)

Does nothing.

static compnd(line, lineno=0)

Does nothing.

conect(line, lineno=0)[source]

Parse a CONECT record. The line is stored for later processing.

Parameters:
  • line (str) – The line to parse. Should start with CONECT, but this is not checked

  • lineno (int) – The line number (not used).

cryst1(line, lineno=0)[source]

Parse the CRYST1 record. Crystal structure information are stored with the parser object and may be extracted later.

static dbref(line, lineno=0)

Does nothing.

static dbref1(line, lineno=0)

Does nothing.

static dbref2(line, lineno=0)

Does nothing.

dispatch(line)[source]

Returns the appropriate method for parsing line. This is determined based on the first 6 characters of line.

Parameters:

line (str) –

Returns:

The method to call with the line, and the line number.

Return type:

collections.abc.Callable[str, int]

do_conect()[source]

Apply connections to molecule based on CONECT records read from PDB file

end(line='', lineno=0)

Finish parsing the molecule. active_molecule will be appended to molecules, and a new active_molecule will be made.

endmdl(line='', lineno=0)

Finish parsing the molecule. active_molecule will be appended to molecules, and a new active_molecule will be made.

static expdta(line, lineno=0)

Does nothing.

finalize(lineno=0)[source]

Finish parsing the file. Process all CONECT records found, and returns a list of molecules.

Parameters:

lineno (int) – The line number (not used).

Returns:

All molecules parsed from this file.

Return type:

list[vermouth.molecule.Molecule]

static formul(line, lineno=0)

Does nothing.

static header(line, lineno=0)

Does nothing.

static helix(line, lineno=0)

Does nothing.

static het(line, lineno=0)

Does nothing.

hetatm(line, lineno=0)

Parse an ATOM or HETATM record.

Parameters:
  • line (str) – The line to parse. We do not check whether it starts with either “ATOM “ or “HETATM”.

  • lineno (int) – The line number (not used).

static hetnam(line, lineno=0)

Does nothing.

static hetsyn(line, lineno=0)

Does nothing.

static jrnl(line, lineno=0)

Does nothing.

static keywds(line, lineno=0)

Does nothing.

Does nothing.

static master(line, lineno=0)

Does nothing.

static mdltyp(line, lineno=0)

Does nothing.

model(line, lineno=0)[source]

Parse a MODEL record. If the model is not the same as modelidx, this model will not be parsed.

Parameters:
  • line (str) – The line to parse. Should start with “MODEL “, but this is not checked.

  • lineno (int) – The line number (not used).

static modres(line, lineno=0)

Does nothing.

static mtrix1(line, lineno=0)

Does nothing.

static mtrix2(line, lineno=0)

Does nothing.

static mtrix3(line, lineno=0)

Does nothing.

static nummdl(line, lineno=0)

Does nothing.

static obslte(line, lineno=0)

Does nothing.

static origx1(line, lineno=0)

Does nothing.

static origx2(line, lineno=0)

Does nothing.

static origx3(line, lineno=0)

Does nothing.

parse(file_handle)[source]
static remark(line, lineno=0)

Does nothing.

static revdat(line, lineno=0)

Does nothing.

static scale1(line, lineno=0)

Does nothing.

static scale2(line, lineno=0)

Does nothing.

static scale3(line, lineno=0)

Does nothing.

static seqadv(line, lineno=0)

Does nothing.

static seqres(line, lineno=0)

Does nothing.

static sheet(line, lineno=0)

Does nothing.

static site(line, lineno=0)

Does nothing.

static source(line, lineno=0)

Does nothing.

static splt(line, lineno=0)

Does nothing.

static sprsde(line, lineno=0)

Does nothing.

static ssbond(line, lineno=0)

Does nothing.

ter(line='', lineno=0)

Finish parsing the molecule. active_molecule will be appended to molecules, and a new active_molecule will be made.

static title(line, lineno=0)

Does nothing.

vermouth.pdb.pdb.get_not_none(node, attr, default)[source]

Returns node[attr]. If it doesn’t exists or is None, return default.

Parameters:
Returns:

The value of node[attr] if it exists and is not None, else default.

Return type:

object

vermouth.pdb.pdb.read_pdb(file_name, exclude=('SOL',), ignh=False, modelidx=1)[source]

Parse a PDB file to create a molecule.

Parameters:
  • filename (str) – The file to read.

  • exclude (collections.abc.Container[str]) – Atoms that have one of these residue names will not be included.

  • ignh (bool) – Whether hydrogen atoms should be ignored.

  • model (int) – If the PDB file contains multiple models, which one to select.

Returns:

The parsed molecules. Will only contain edges if the PDB file has CONECT records. Either way, the molecules might be disconnected. Entries separated by TER, ENDMDL, and END records will result in separate molecules.

Return type:

list[vermouth.molecule.Molecule]

vermouth.pdb.pdb.write_pdb(system, path, conect=True, omit_charges=True, nan_missing_pos=False, defer_writing=True)[source]

Writes system to path as a PDB formatted string.

Parameters:
  • system (vermouth.system.System) – The system to write.

  • path (str) – The file to write to.

  • conect (bool) – Whether to write CONECT records for the edges.

  • omit_charges (bool) – Whether charges should be omitted. This is usually a good idea since the PDB format can only deal with integer charges.

  • nan_missing_pos (bool) – Whether the writing should fail if an atom does not have a position. When set to True, atoms without coordinates will be written with ‘nan’ as coordinates; this will cause the output file to be invalid for most uses. for most use.

  • defer_writing (bool) – Whether to use DeferredFileWriter for writing data

See also

:func:write_pdb_string

vermouth.pdb.pdb.write_pdb_string(system, conect=True, omit_charges=True, nan_missing_pos=False)[source]

Describes system as a PDB formatted string. Will create CONECT records from the edges in the molecules in system iff conect is True.

Parameters:
  • system (vermouth.system.System) – The system to write.

  • conect (bool) – Whether to write CONECT records for the edges.

  • omit_charges (bool) – Whether charges should be omitted. This is usually a good idea since the PDB format can only deal with integer charges.

  • nan_missing_pos (bool) – Wether the writing should fail if an atom does not have a position. When set to True, atoms without coordinates will be written with ‘nan’ as coordinates; this will cause the output file to be invalid for most uses.

Returns:

The system as PDB formatted string.

Return type:

str