pytraj.topology

class pytraj.topology.Topology

Bases: object

Attributes

angle_indices
angles
atom_names return unique atom name in Topology
atomlist return a copy of atoms. If the Topology is large, this method calling
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)
moleculelist return a copy of molecules. (not much information)
mols
n_atoms
n_mols
n_residues
n_solvents
residue_names return unique residue names in Topology
residuelist return a copy of residues
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)
indices_bonded_to(self, atom_name) return indices of the number of atoms that each atom bonds to
is_empty(self)
join(self, Topology top)
load(self, string filename) loading Topology from filename. This is for internal use. Should pytraj.load_topology
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_distance_mask_reference(self, Frame frame)
set_integer_mask(self, AtomMask atm, ...)
set_nobox(self)
set_solvent(self, mask) set mask as solvent
simplify(...) return a (immutable) light version of Topology for fast iterating. (experiment)
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_dataframe(...) convert to pandas’ DataFrame. (experiment)
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

atom_names

return unique atom name in Topology

atomlist

return a copy of atoms. If the Topology is large, this method calling is every expensive. Make sure to call once and save it.

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)
indices_bonded_to(self, atom_name)

return indices of the number of atoms that each atom bonds to

Parameters:atom_name : name of the atom
is_empty(self)
join(self, Topology top)
load(self, string filename)

loading Topology from filename. This is for internal use. Should pytraj.load_topology

mass

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

moleculelist

return a copy of molecules. (not much information)

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 ()

residue_names

return unique residue names in Topology

residuelist

return a copy of residues

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_distance_mask_reference(self, Frame frame)
set_integer_mask(self, AtomMask atm, Frame frame=<???>)
set_nobox(self)
set_solvent(self, mask)

set mask as solvent

simplify(self) return a (immutable) light version of Topology for fast iterating. (experiment)

return a (immutable) light version of Topology for fast iterating. (experiment)

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_dataframe(self) convert to pandas' DataFrame. (experiment)

convert to pandas’ DataFrame. (experiment)

to_dict(self)

convert Topology to Python dict

to_parmed(self)

try to load to ParmEd’s Structure

class pytraj.topology.ParmFile

Bases: object

Methods

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

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

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

Bases: importlib._bootstrap.SimplifiedTopology

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

Notes

cpptraj does not understand this class (use :class:Topology)

Attributes

atoms Alias for field number 0
residues Alias for field number 1

Methods

count(...)
index((value, [start, ...) Raises ValueError if the value is not present.
atoms

Alias for field number 0

count(value) → integer -- return number of occurrences of value
index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

residues

Alias for field number 1

class pytraj.topology.SimplifiedAtom(name, type, element, charge, mass, index, atomic_number, resname, resid, molnum)

Bases: importlib._bootstrap.SimplifiedAtom

Attributes

atomic_number Alias for field number 6
charge Alias for field number 3
element Alias for field number 2
index Alias for field number 5
mass Alias for field number 4
molnum Alias for field number 9
name Alias for field number 0
resid Alias for field number 8
resname Alias for field number 7
type Alias for field number 1

Methods

count(...)
atomic_number

Alias for field number 6

charge

Alias for field number 3

count(value) → integer -- return number of occurrences of value
element

Alias for field number 2

index

Alias for field number 5

mass

Alias for field number 4

molnum

Alias for field number 9

name

Alias for field number 0

resid

Alias for field number 8

resname

Alias for field number 7

type

Alias for field number 1

class pytraj.topology.SimplifiedResidue(name, index, first, last)

Bases: importlib._bootstrap.SimplifiedResidue

Attributes

first Alias for field number 2
index Alias for field number 1
last Alias for field number 3
name Alias for field number 0

Methods

count(...)
count(value) → integer -- return number of occurrences of value
first

Alias for field number 2

index

Alias for field number 1

last

Alias for field number 3

name

Alias for field number 0