pytraj.topology

class pytraj.topology.topology.Topology

Bases: object

Attributes

angle_indices
angles
atoms
bond_indices
bonds
box
charge return a copy of atom charges (numpy 1D array)
dihedral_indices
dihedrals
filename return original filename. This is for testing purpose.
mass return a copy of atom masses (numpy 1D array)
mols
n_atoms
n_mols
n_residues
n_solvents
residues

Methods

__call__ intended to use with Frame indexing: atm = top('@CA‘) (for internal use)
add_angles add angle for a group of 3 atoms.
add_atom(self, Atom atom, Residue residue)
add_bonds add bond for pairs of atoms.
add_dihedrals add dihedral for a group of 4 atoms.
atom(self, int idx) return an Atom based on idx. Update this Atom will update Topology.
atom_indices(self, mask, \*args, \*\*kwd) return atom indices with given mask
copy(self, \*args) Return a copy of ‘self’ or copy from ‘other’ to ‘self’
from_dict(type cls, dict_data) internal use for serialize Topology
has_box(self)
is_empty(self)
join(self, Topology top)
residue(self, int idx, bool atom=False) if atom is True, get full list of atoms for idx-th residue. This will be very slow
save(self[, filename, format]) save to given file format (parm7, psf, ...)
select(self, mask) return atom indices
set_nobox(self)
set_reference(self, Frame frame) Set reference frame for distance-based mask
set_solvent(self, mask) set mask as solvent
simplify(self) return a (immutable) lightweight version of Topology for fast iterating.
start_new_mol(self)
strip(self, mask[, copy]) strip atoms with given mask
summary(...) basic info. This information only appears in Ipython or Python shell.
to_dict(self) convert Topology to Python dict
to_parmed(self) try to load to ParmEd’s Structure
add_angles

add angle for a group of 3 atoms.

Parameters:

indices : 2D array_like (must have buffer interface),

shape=(n_atoms, 3)

add_atom(self, Atom atom, Residue residue)
add_bonds

add bond for pairs of atoms.

Parameters:

bond_indices : 2D array_like (must have buffer interface)

shape=(n_atoms, 2)

add_dihedrals

add dihedral for a group of 4 atoms.

Parameters:

indices : 2D array_like (must have buffer interface),

shape=(n_atoms, 3)

angle_indices
angles
atom(self, int idx)

return an Atom based on idx. Update this Atom will update Topology. Make this method private for now.

atom_indices(self, mask, *args, **kwd)

return atom indices with given mask To be the same as cpptraj/Ambertools: we mask indexing starts from 1 but the return list/array use 0

Parameters:

mask : str

Atom mask

Returns

——

indices : Python array

atoms
bond_indices
bonds
box
charge

return a copy of atom charges (numpy 1D array)

copy(self, *args)

Return a copy of ‘self’ or copy from ‘other’ to ‘self’ TODO : add more doc

dihedral_indices
dihedrals
filename

return original filename. This is for testing purpose.

from_dict(type cls, dict_data)

internal use for serialize Topology

has_box(self)
is_empty(self)
join(self, Topology top)
mass

return a copy of atom masses (numpy 1D array)

mols
n_atoms
n_mols
n_residues
n_solvents
residue(self, int idx, bool atom=False)

if atom is True, get full list of atoms for idx-th residue. This will be very slow if atom is False, get ()

residues
save(self, filename=None, format='AMBERPARM') save to given file format (parm7, psf, ...)

save to given file format (parm7, psf, ...)

select(self, mask)

return atom indices

Notes

support openmp for distance-based atommask selction

Examples

>>> import pytraj as pt
>>> traj = pt.datafiles.load_tz2()
>>> atm = traj.top.select("@CA")
>>> atm
array([  4,  15,  39, ..., 159, 173, 197])
>>> pt.rmsd(traj, mask=atm)
array([  1.94667955e-07,   2.54596866e+00,   4.22333034e+00, ...,
         4.97189564e+00,   5.53947712e+00,   4.83201237e+00])
set_nobox(self)
set_reference(self, Frame frame)

Set reference frame for distance-based mask

Parameters:

frame : Frame

reference frame

set_solvent(self, mask)

set mask as solvent

simplify(self)

return a (immutable) lightweight version of Topology for fast iterating. The API is not stable.

No writing capabibility (you should use ParmEd for Topology editing)

Examples

>>> import pytraj as pt
>>> top = pt.load_topology('data/tz2.parm7')
>>> simp_top = top.simplify()
>>> atom = simp_top.atoms[0]
>>> atom.resname
'SER'
>>> res = simp_top.residues[0]
>>> # get all atoms for 1st residue
>>> atoms = simp_top.atoms[res.first:res.last]
start_new_mol(self)
strip(self, mask, copy=False)

strip atoms with given mask

summary(self) basic info. This information only appears in Ipython or Python shell. It does not appear in Jupyter notebook (due to C++ stdout)

basic info. This information only appears in Ipython or Python shell. It does not appear in Jupyter notebook (due to C++ stdout)

to_dict(self)

convert Topology to Python dict

to_parmed(self)

try to load to ParmEd’s Structure

class pytraj.topology.topology.ParmFile

Bases: object

Methods

filename(self)
read(self[, filename, top, option]) top : Topology instance
write(self, Topology top=<???>[, filename, ...])
filename(self)
read(self, filename='', top=<???>, option='') read(Topology top=Topology(), string filename="", "*args) Return : None (update `top`)

top : Topology instance filename : str, output filename arglist : ArgList instance, optional

write(self, Topology top=<???>, filename='default.top', ArgList arglist=<???>, format='')
class pytraj.topology.topology.SimplifiedTopology

Bases: object

EXPERIMENTAL: a lightweight Topology for fast iterating and convenient accessing atom, residue

Notes

  • cpptraj does not understand this class (use :class:Topology)
  • read only

Methods

select(self, mask)
select(self, mask)
class pytraj.topology.topology.SimplifiedAtom

Bases: object

EXPERIMENTAL

read only

Attributes

bond_partners
residue
bond_partners
residue
class pytraj.topology.topology.SimplifiedResidue

Bases: object

EXPERIMENTAL

read only

Attributes

atoms
atoms