pytraj.topology

class pytraj.topology.Topology

Bases: object

Attributes

angle_indices
angles
atom_names
atomlist return a copy of a list 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
mass return a copy of atom masses (numpy 1D array)
moleculelist
mols
n_atoms
n_mols
n_residues
n_solvents
residue_names
residuelist
residues
vdw_radii

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)
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])
select(self, mask) return AtomMask object
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(self) get a light version (immutable) of Topology for fast iterating
start_new_mol(self)
strip(self, mask[, copy]) strip atoms with given mask
summary(self)
to_dataframe(self)
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
atomlist

return a copy of a list of atoms. If the Topology is large, this method calling is every expensive. Make sure to save atomlist.

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
from_dict(type cls, dict_data)
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
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
residuelist
residues
save(self, filename=None, format='AMBERPARM')
select(self, mask)

return AtomMask object

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)

get a light version (immutable) of Topology for fast iterating

start_new_mol(self)
strip(self, mask, copy=False)

strip atoms with given mask

summary(self)
to_dataframe(self)
to_dict(self)

convert Topology to Python dict

to_parmed(self)

try to load to ParmEd’s Structure

vdw_radii
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_atom_index, last_atom_index)

Bases: importlib._bootstrap.SimplifiedResidue

Attributes

first_atom_index Alias for field number 2
index Alias for field number 1
last_atom_index Alias for field number 3
name Alias for field number 0

Methods

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

Alias for field number 2

index

Alias for field number 1

last_atom_index

Alias for field number 3

name

Alias for field number 0