parmed.charmm package

Module contents

This package contains code for reading CHARMM structure files for setting up a simulation with CHARMM; specifically PSF, PAR, RTF, and STR files

  • PAR
    : Parameter file (PRM) – this contains all of the force field
    parameters (e.g., bond lengths and strengths) for all of the atom types
  • RTF
    : Residue Topology File – this file contains the residue
    connectivity tables as well as a definition of all of the atom types. Also contains an internal coordinate representation of the residues
  • PSF
    : Protein Structure File – this is the main file type in CHARMM
    simulations that defines all of the residues in a system as well as the atom types and connectivity between the atoms
  • STR
    : Stream file – Source of additional information and CHARMM commands
    that can contain RTF and PAR information. Allows users to define additional parameters without ‘contaminating’ the original force field parameter files
class parmed.charmm.CharmmPsfFile(psf_name=None)[source]

Bases: parmed.structure.Structure

A chemical Structure instantiated from CHARMM files.

Parameters:

psf_name : str, optional

Name of the PSF file (it must exist)

Raises:

IOError : If file psf_name does not exist

CharmmPsfError : If any parsing errors are encountered

Attributes

box
box_vectors 3, 3-element tuple of unit cell vectors that are Quantity objects of
combining_rule
coordinates
positions A list of 3-element Quantity tuples of dimension length representing the atomic positions for every atom in the system.
topology The OpenMM Topology object.
velocities A (natom, 3)-shape numpy array with atomic velocities for every atom in
view Returns an indexable object that can be indexed like a standard

Methods

add_atom(atom, resname, resnum[, chain, ...]) Adds a new atom to the Structure, adding a new residue to residues if it has a different name or number as the last residue added and adding it to the atoms list.
add_atom_to_residue(atom, residue) Adds a new atom to the Structure at the end if the given residue
assign_bonds(\*reslibs) Assigns bonds to all atoms based on the provided residue template libraries.
clear_cmap() Clear the cmap list to prevent any CMAP parameters from being used
copy(cls[, split_dihedrals]) Makes a copy of the current structure as an instance of a specified
createSystem([params]) Creates an OpenMM System object from the CHARMM PSF file.
from_structure(struct[, copy]) Instantiates a CharmmPsfFile from an input Structure instance.
get_box([frame]) In some cases, multiple conformations may be stored in the Structure.
get_coordinates([frame]) In some cases, multiple conformations may be stored in the Structure.
has_NBFIX() Returns whether or not any pairs of atom types have their LJ
is_changed() Determines if any of the topology has changed for this structure
join_dihedrals() Joins multi-term torsions into a single term and makes all of the parameters DihedralTypeList instances.
load_dataframe(df) Loads atomic properties from an input DataFrame
load_parameters(parmset[, copy_parameters]) Loads parameters from a parameter set that was loaded via CHARMM RTF, PAR, and STR files.
omm_add_constraints(system, constraints, ...) Adds constraints to a given system
omm_angle_force([constraints, ...]) Creates an OpenMM HarmonicAngleForce object (or AmoebaAngleForce if the
omm_bond_force([constraints, rigidWater, ...]) Creates an OpenMM Bond Force object (or AmoebaBondForce if the bonds are
omm_cmap_force() Creates the OpenMM CMAP torsion force
omm_dihedral_force([split]) Creates the OpenMM PeriodicTorsionForce modeling dihedrals
omm_gbsa_force(implicitSolvent[, ...]) Creates a Generalized Born force for running implicit solvent
omm_improper_force() Creates the OpenMM improper torsion force (quadratic bias)
omm_nonbonded_force([nonbondedMethod, ...]) Creates the OpenMM NonbondedForce instance
omm_out_of_plane_bend_force() Creates the Amoeba out-of-plane bend force
omm_pi_torsion_force() Creates the Amoeba pi-torsion force
omm_rb_torsion_force() Creates the OpenMM RBTorsionForce for Ryckaert-Bellemans torsions
omm_set_virtual_sites(system) Sets the virtual sites in a given OpenMM System object from the extra
omm_stretch_bend_force() Create the OpenMM Amoeba stretch-bend force for this system
omm_torsion_torsion_force() Create the OpenMM Amoeba coupled-torsion (CMAP) force
omm_trigonal_angle_force() Creates the Amoeba trigonal-angle force
omm_urey_bradley_force() Creates the OpenMM Urey-Bradley force
prune_empty_terms() Looks through all of the topological lists and gets rid of terms
save(fname[, format, overwrite]) Saves the current Structure in the requested file format.
split() Split the current Structure into separate Structure instances for each unique molecule.
strip(selection) Deletes a subset of the atoms corresponding to an atom-based selection.
to_dataframe() Generates a DataFrame from the current Structure’s atomic properties
unchange() Toggles all lists so that they do not indicate any changes
update_dihedral_exclusions() Nonbonded exclusions and exceptions have the following priority:
visualize(\*args, \*\*kwargs) Use nglview for visualization.
write_cif(struct, dest[, renumber, ...]) Write a PDB file from the current Structure instance
write_pdb(struct, dest[, renumber, ...]) Write a PDB file from a Structure instance
write_psf(struct, dest[, vmd]) Writes a PSF file from the stored molecule
ANGLE_FORCE_GROUP = 1
BOND_FORCE_GROUP = 0
CMAP_FORCE_GROUP = 5
DIHEDRAL_FORCE_GROUP = 2
IMPROPER_FORCE_GROUP = 4
NONBONDED_FORCE_GROUP = 11
OUT_OF_PLANE_BEND_FORCE_GROUP = 7
PI_TORSION_FORCE_GROUP = 8
RB_TORSION_FORCE_GROUP = 12
STRETCH_BEND_FORCE_GROUP = 9
TORSION_TORSION_FORCE_GROUP = 10
TRIGONAL_ANGLE_FORCE_GROUP = 6
UREY_BRADLEY_FORCE_GROUP = 3
add_atom(atom, resname, resnum, chain='', inscode='', segid='')

Adds a new atom to the Structure, adding a new residue to residues if it has a different name or number as the last residue added and adding it to the atoms list.

Parameters:

atom : Atom

The atom to add to this residue list

resname : str

The name of the residue this atom belongs to

resnum : int

The number of the residue this atom belongs to

chain : str

The chain ID character for this residue

inscode : str

The insertion code ID character for this residue (it is stripped)

segid : str

The segment identifier for this residue (it is stripped)

Notes

If the residue name and number differ from the last residue in this list, a new residue is added and the atom is added to that residue

add_atom_to_residue(atom, residue)

Adds a new atom to the Structure at the end if the given residue

Parameters:

atom : Atom

The atom to add to the system

residue : Residue

The residue to which to add this atom. It MUST be part of this Structure instance already or a ValueError is raised

Notes

This atom is added at the end of the residue and is inserted into the atoms list in such a way that all residues are composed of atoms contiguous in the atoms list. For large systems, this may be a relatively expensive operation

assign_bonds(*reslibs)

Assigns bonds to all atoms based on the provided residue template libraries. Atoms whose names are not in the templates, as well as those residues for whom no template is found, is assigned to bonds based on distances.

Parameters:

reslibs : dict{str: ResidueTemplate}

Any number of residue template libraries. By default, assign_bonds knows about the standard amino acid, RNA, and DNA residues.

box
box_vectors

3, 3-element tuple of unit cell vectors that are Quantity objects of dimension length

clear_cmap()[source]

Clear the cmap list to prevent any CMAP parameters from being used

combining_rule
coordinates
copy(cls, split_dihedrals=False)

Makes a copy of the current structure as an instance of a specified subclass

Parameters:

cls : Structure subclass

The returned object is a copy of this structure as a cls instance

split_dihedrals : bool

If True, then the Dihedral entries will be split up so that each one is paired with a single DihedralType (rather than a DihedralTypeList)

Returns:

cls instance

The instance of the Structure subclass cls with a copy of the current Structure’s topology information

createSystem(params=None, *args, **kwargs)[source]

Creates an OpenMM System object from the CHARMM PSF file. This is a shortcut for calling load_parameters followed by Structure.createSystem. If params is not None, load_parameters will be called on that parameter set, and Structure.createSystem will be called with the remaining args and kwargs

Parameters:

params : CharmmParameterSet=None

If not None, this parameter set will be loaded

See also

parmed.structure.Structure.createSystem()
In addition to params, this method also takes all arguments for parmed.structure.Structure.createSystem()
classmethod from_structure(struct, copy=False)[source]

Instantiates a CharmmPsfFile from an input Structure instance. This method makes sure all atom types have uppercase-only names

Parameters:

struct : parmed.structure.Structure

The input structure to convert to a CharmmPsfFile instance

copy : bool, optional

If True, a copy of all items are made. Otherwise, the resulting CharmmPsfFile is a shallow copy

Returns:

psf : CharmmPsfFile

CHARMM PSF file

Raises:

ValueError if the functional form is not recognized or cannot be

implemented through the PSF and parameter/stream files

Notes

If copy is False, the original object may have its atom type names changed if any of them have lower-case letters

get_box(frame='all')

In some cases, multiple conformations may be stored in the Structure. This function retrieves a particular frame’s unit cell (box) dimensions

Parameters:

frame : int or ‘all’, optional

The frame number whose unit cell should be retrieved. Default is ‘all’

Returns:

box : np.ndarray, shape([#,] 6) or None

If frame is ‘all’, all unit cells are returned with shape (#, 6). Otherwise the requested frame is returned with shape (6,). If no unit cell exist and ‘all’ is requested, None is returned

Raises:

IndexError if there are fewer than ``frame`` unit cell dimensions

get_coordinates(frame='all')

In some cases, multiple conformations may be stored in the Structure. This function retrieves a particular frame’s coordinates

Parameters:

frame : int or ‘all’, optional

The frame number whose coordinates should be retrieved. Default is ‘all’

Returns:

coords : np.ndarray, shape([#,] natom, 3) or None

If frame is ‘all’, all coordinates are returned with shape (#, natom, 3). Otherwise the requested frame is returned with shape (natom, 3). If no coordinates exist and ‘all’ is requested, None is returned

Raises:

IndexError if there are fewer than ``frame`` coordinates

has_NBFIX()

Returns whether or not any pairs of atom types have their LJ interactions modified by an NBFIX definition

Returns:

has_nbfix : bool

If True, at least two atom types have NBFIX mod definitions

is_changed()

Determines if any of the topology has changed for this structure

join_dihedrals()

Joins multi-term torsions into a single term and makes all of the parameters DihedralTypeList instances. If any dihedrals are already DihedralTypeList instances, or any are not parametrized, or there are no dihedral_types, this method returns without doing anything

load_dataframe(df)

Loads atomic properties from an input DataFrame

Parameters:

df : pandas.DataFrame

A pandas DataFrame with atomic properties that will be used to set the properties on the current list of atoms

load_parameters(parmset, copy_parameters=True)[source]

Loads parameters from a parameter set that was loaded via CHARMM RTF, PAR, and STR files.

Parameters:

parmset : CharmmParameterSet

List of all parameters

copy_parameters : bool, optional, default=True

If False, parmset will not be copied.

Not copying parmset will cause ParameterSet and Structure to share references to types. If you modify the original parameter set, the references in Structure list_types will be silently modified. However, if you change any reference in the parameter set, then that reference will no longer be shared with structure.

Example where the reference in ParameterSet is changed. The following will NOT modify the parameters in the psf:

psf.load_parameters(parmset, copy_parameters=False)
parmset.angle_types[('a1', 'a2', a3')] = AngleType(1, 2)

The following WILL change the parameter in the psf because the reference has not been changed in ParameterSet:

psf.load_parameters(parmset, copy_parameters=False)
a = parmset.angle_types[('a1', 'a2', 'a3')]
a.k = 10
a.theteq = 100

Extra care should be taken when trying this with dihedral_types. Since dihedral_type is a Fourier sequence, ParameterSet stores DihedralType for every term in DihedralTypeList. Therefore, the example below will STILL modify the type in the Structure list_types:

parmset.dihedral_types[('a', 'b', 'c', 'd')][0] = DihedralType(1, 2, 3)

This assigns a new instance of DihedralType to an existing DihedralTypeList that ParameterSet and Structure are tracking and the shared reference is NOT changed.

Use with caution!

Raises:

ParameterError if any parameters cannot be found

Notes

  • If any dihedral or improper parameters cannot be found, I will try inserting wildcards (at either end for dihedrals and as the two central atoms in impropers) and see if that matches. Wild-cards will apply ONLY if specific parameters cannot be found.
  • This method will expand the dihedrals attribute by adding a separate Dihedral object for each term for types that have a multi-term expansion
omm_add_constraints(system, constraints, rigidWater)

Adds constraints to a given system

Parameters:

system : mm.System

The OpenMM system for which constraints should be added

constraints : None, app.HBonds, app.AllBonds, or app.HAngles

Which kind of constraints should be used

rigidWater : bool

If True, water bonds are constrained regardless of whether constrains is None

omm_angle_force(constraints=None, flexibleConstraints=True)

Creates an OpenMM HarmonicAngleForce object (or AmoebaAngleForce if the angles are for an Amoeba-parametrized system)

Parameters:

constraints : None, app.HBonds, app.AllBonds, or app.HAngles

The types of constraints that are on the system. If flexibleConstraints is False, then the constrained bonds will not be added to the resulting Force

flexibleConstraints : bool=True

If True, all bonds are added to the force regardless of constraints

Returns:

force

HarmonicAngleForce (or AmoebaAngleForce if this is an Amoeba system), or None if there are no angles to add

omm_bond_force(constraints=None, rigidWater=True, flexibleConstraints=True)

Creates an OpenMM Bond Force object (or AmoebaBondForce if the bonds are for an Amoeba-parametrized system)

Parameters:

constraints : None, app.HBonds, app.AllBonds, or app.HAngles

The types of constraints that are on the system. If flexibleConstraints is False, then the constrained bonds will not be added to the resulting Force

rigidWater : bool=True

Should water-H bonds be constrained regardless of constraints?

flexibleConstraints : bool=True

If True, all bonds are added to the force regardless of constraints

Returns:

force

HarmonicBondForce (or AmoebaBondForce if this is an Amoeba system), or None if there are no bonds to add

omm_cmap_force()

Creates the OpenMM CMAP torsion force

Returns:

CMAPTorsionForce

Or None, if no CMAP terms are present

omm_dihedral_force(split=False)

Creates the OpenMM PeriodicTorsionForce modeling dihedrals

Parameters:

split : bool, optional, default=False

If True, separate PeriodicTorsionForce instances with the propers in the first and impropers in the second return item. If no impropers or propers are present, the instances with zero terms are not returned.

Returns:

PeriodicTorsionForce[, PeriodicTorsionForce]

Or None if no torsions are present in this system

omm_gbsa_force(implicitSolvent, nonbondedMethod=None, nonbondedCutoff=Quantity(value=30.0, unit=angstrom), soluteDielectric=1.0, solventDielectric=78.5, implicitSolventKappa=None, implicitSolventSaltConc=Quantity(value=0.0, unit=mole/liter), temperature=Quantity(value=298.15, unit=kelvin), useSASA=True)

Creates a Generalized Born force for running implicit solvent calculations

Parameters:

implicitSolvent : app.HCT, app.OBC1, app.OBC2, app.GBn, app.GBn2

The Generalized Born implicit solvent model to use.

nonbondedMethod : cutoff method

This is the cutoff method. It can be either the NoCutoff, CutoffNonPeriodic, CutoffPeriodic, PME, or Ewald objects from the simtk.openmm.app namespace. Default is NoCutoff

nonbondedCutoff : float or distance Quantity

The nonbonded cutoff must be either a floating opint number (interpreted as nanometers) or a Quantity with attached units. This is ignored if nonbondedMethod is NoCutoff

implicitSolventKappa : float or 1/distance Quantity = None

This is the Debye kappa property related to modeling saltwater conditions in GB. It should have units of 1/distance (1/nanometers is assumed if no units present). A value of None means that kappa will be calculated from implicitSolventSaltConc (below)

implicitSolventSaltConc : float or amount/volume Quantity=0 moles/liter

If implicitSolventKappa is None, the kappa will be computed from the salt concentration. It should have units compatible with mol/L

temperature : float or temperature Quantity = 298.15 kelvin

This is only used to compute kappa from implicitSolventSaltConc

soluteDielectric : float=1.0

The dielectric constant of the protein interior used in GB

solventDielectric : float=78.5

The dielectric constant of the water used in GB

omm_improper_force()

Creates the OpenMM improper torsion force (quadratic bias)

Returns:

CustomTorsionForce

With the formula k*(phi-phi0)^2, or None if there are no impropers

omm_nonbonded_force(nonbondedMethod=None, nonbondedCutoff=Quantity(value=8, unit=angstrom), switchDistance=Quantity(value=0, unit=angstrom), ewaldErrorTolerance=0.0005, reactionFieldDielectric=78.5)

Creates the OpenMM NonbondedForce instance

Parameters:

nonbondedMethod : cutoff method

This is the cutoff method. It can be either the NoCutoff, CutoffNonPeriodic, CutoffPeriodic, PME, or Ewald objects from the simtk.openmm.app namespace

nonbondedCutoff : float or distance Quantity

The nonbonded cutoff must be either a floating point number (interpreted as nanometers) or a Quantity with attached units. This is ignored if nonbondedMethod is NoCutoff.

switchDistance : float or distance Quantity

The distance at which the switching function is turned on for van der Waals interactions. This is ignored when no cutoff is used, and no switch is used if switchDistance is 0, negative, or greater than the cutoff

ewaldErrorTolerance : float=0.0005

When using PME or Ewald, the Ewald parameters will be calculated from this value

reactionFieldDielectric : float=78.5

If the nonbondedMethod is CutoffPeriodic or CutoffNonPeriodic, the region beyond the cutoff is treated using a reaction field method with this dielectric constant. It should be set to 1 if another implicit solvent model is being used (e.g., GB)

Returns:

NonbondedForce

This just implements the very basic NonbondedForce with the typical charge-charge and 12-6 Lennard-Jones interactions with the Lorentz-Berthelot combining rules.

Notes

Subclasses of Structure for which this nonbonded treatment is inadequate should override this method to implement what is needed.

If nrexcl is set to 3 and no exception parameters are stored in the adjusts list, the 1-4 interactions are determined from the list of dihedrals

omm_out_of_plane_bend_force()

Creates the Amoeba out-of-plane bend force

Returns:

AmoebaOutOfPlaneBendForce

The out-of-plane bend Angle force

omm_pi_torsion_force()

Creates the Amoeba pi-torsion force

Returns:

AmoebaPiTorsionForce

The pi-torsion force

omm_rb_torsion_force()

Creates the OpenMM RBTorsionForce for Ryckaert-Bellemans torsions

Returns:

RBTorsionForce

Or None if no torsions are present in this system

omm_set_virtual_sites(system)

Sets the virtual sites in a given OpenMM System object from the extra points defined in this system

Parameters:

system : mm.System

The system for which the virtual sites will be set. All particles must have already been added to this System before calling this method

omm_stretch_bend_force()

Create the OpenMM Amoeba stretch-bend force for this system

Returns:

AmoebaStretchBendForce

The stretch-bend force containing all terms in this system

omm_torsion_torsion_force()

Create the OpenMM Amoeba coupled-torsion (CMAP) force

Returns:

AmoebaTorsionTorsionForce

The torsion-torsion (CMAP) force with all coupled-torsion parameters for this system

omm_trigonal_angle_force()

Creates the Amoeba trigonal-angle force

Returns:

AmoebaInPlaneAngleForce

The trigonal in-plane Angle force

omm_urey_bradley_force()

Creates the OpenMM Urey-Bradley force

Returns:

HarmonicBondForce

Or None, if no urey-bradleys are present

positions

A list of 3-element Quantity tuples of dimension length representing the atomic positions for every atom in the system. If set with unitless numbers, those numbers are assumed to be in angstroms. If any atoms do not have coordinates, this is simply None.

prune_empty_terms()

Looks through all of the topological lists and gets rid of terms in which at least one of the atoms is None or has an idx attribute set to -1 (indicating that it has been removed from the atoms atom list)

save(fname, format=None, overwrite=False, **kwargs)

Saves the current Structure in the requested file format. Supported formats can be specified explicitly or determined by file-name extension. The following formats are supported, with the recognized suffix and format keyword shown in parentheses:

  • PDB (.pdb, pdb)
  • PDBx/mmCIF (.cif, cif)
  • PQR (.pqr, pqr)
  • Amber topology file (.prmtop/.parm7, amber)
  • CHARMM PSF file (.psf, psf)
  • CHARMM coordinate file (.crd, charmmcrd)
  • Gromacs topology file (.top, gromacs)
  • Gromacs GRO file (.gro, gro)
  • Mol2 file (.mol2, mol2)
  • Mol3 file (.mol3, mol3)
  • Amber ASCII restart (.rst7/.inpcrd/.restrt, rst7)
  • Amber NetCDF restart (.ncrst, ncrst)
Parameters:

fname : str or file-like object

Name of the file or file-like object to save. If format is None (see below), the file type will be determined based on the filename extension. If fname is file-like object, format must be provided. If the type cannot be determined, a ValueError is raised.

format : str, optional

The case-insensitive keyword specifying what type of file fname should be saved as. If None (default), the file type will be determined from filename extension of fname

overwrite : bool, optional

If True, allow the target file to be overwritten. Otherwise, an IOError is raised if the file exists. Default is False

kwargs : keyword-arguments

Remaining arguments are passed on to the file writing routines that are called by this function

Raises:

ValueError if either filename extension or ``format`` are not recognized

TypeError if the structure cannot be converted to the desired format for

whatever reason

IOError if the file cannot be written either because it exists and

``overwrite`` is ``False``, the filesystem is read-only, or write

permissions are not granted for the user

split()

Split the current Structure into separate Structure instances for each unique molecule. A molecule is defined as all atoms connected by a graph of covalent bonds.

Returns:

[structs, counts] : list of (Structure, list) tuples

List of all molecules in the order that they appear first in the parent structure accompanied by the list of the molecule numbers in which that molecule appears in the Structure

strip(selection)

Deletes a subset of the atoms corresponding to an atom-based selection.

Parameters:

selection : AmberMask, str, or iterable

This is the selection of atoms that will be deleted from this structure. If it is a string, it will be interpreted as an AmberMask. If it is an AmberMask, it will be converted to a selection of atoms. If it is an iterable, it must be the same length as the atoms list.

to_dataframe()

Generates a DataFrame from the current Structure’s atomic properties

Returns:

df : DataFrame

DataFrame with all atomic properties

topology

The OpenMM Topology object. Cached when possible, but any changes to the Structure instance results in the topology being deleted and rebuilt

Notes

This function calls prune_empty_terms if any topology lists have changed.

unchange()

Toggles all lists so that they do not indicate any changes

update_dihedral_exclusions()

Nonbonded exclusions and exceptions have the following priority:

bond -> angle -> dihedral

Since bonds and angles are completely excluded, any ring systems in which two atoms are attached by a bond or angle as well as a dihedral should be completely excluded as the bond and angle exclusion rules take precedence. If a Bond or Angle was _added_ to the structure between a pair of atoms previously connected only by a dihedral term, it’s possible that those two atoms have both an exclusion and an exception defined. The result of this scenario is that sander and pmemd will happily compute an energy, _including_ the 1-4 nonbonded terms between atoms now connected by a bond or an Angle. OpenMM, on the other hand, will complain about an exception specified multiple times. This method scans through all of the dihedrals in which ignore_end is False and turns it to True if the two end atoms are in the bond or angle partners arrays

velocities

A (natom, 3)-shape numpy array with atomic velocities for every atom in the system (in units of angstrom/picosecond), or None if there are no velocities

view

Returns an indexable object that can be indexed like a standard Structure, but returns a view rather than a copy

See also

Structure.__getitem__

visualize(*args, **kwargs)

Use nglview for visualization. This only works with Jupyter notebook and require to install nglview

Parameters:args and kwargs : positional and keyword arguments given to nglview, optional

Examples

>>> import parmed as pmd
>>> parm = pmd.download_PDB('1tsu')
>>> parm.visualize()
write_cif(struct, dest, renumber=True, coordinates=None, altlocs='all', write_anisou=False, standard_resnames=False)

Write a PDB file from the current Structure instance

Parameters:

struct : Structure

The structure from which to write the PDBx/mmCIF file

dest : str or file-like

Either a file name or a file-like object containing a write method to which to write the PDB file. If it is a filename that ends with .gz or .bz2, a compressed version will be written using either gzip or bzip2, respectively.

renumber : bool

If True, renumber the atoms and residues sequentially as they are stored in the structure. If False, use the original numbering if it was assigned previously

coordinates : array-like of float

If provided, these coordinates will be written to the PDB file instead of the coordinates stored in the structure. These coordinates should line up with the atom order in the structure (not necessarily the order of the “original” PDB file if they differ)

altlocs : str

Keyword controlling which alternate locations are printed to the resulting PDB file. Allowable options are:

  • ‘all’ : (default) print all alternate locations
  • ‘first’ : print only the first alternate locations
  • ‘occupancy’ : print the one with the largest occupancy. If two conformers have the same occupancy, the first one to occur is printed

Input is case-insensitive, and partial strings are permitted as long as it is a substring of one of the above options that uniquely identifies the choice.

write_anisou : bool

If True, an ANISOU record is written for every atom that has one. If False, ANISOU records are not written

standard_resnames : bool, optional

If True, common aliases for various amino and nucleic acid residues will be converted into the PDB-standard values. Default is False

Notes

If multiple coordinate frames are present, these will be written as separate models (but only the unit cell from the first model will be written, as the PDBx standard dictates that only one set of unit cells shall be present).

write_pdb(struct, dest, renumber=True, coordinates=None, altlocs='all', write_anisou=False, charmm=False, standard_resnames=False)

Write a PDB file from a Structure instance

Parameters:

struct : Structure

The structure from which to write the PDB file

dest : str or file-like

Either a file name or a file-like object containing a write method to which to write the PDB file. If it is a filename that ends with .gz or .bz2, a compressed version will be written using either gzip or bzip2, respectively.

renumber : bool, optional, default True

If True, renumber the atoms and residues sequentially as they are stored in the structure. If False, use the original numbering if it was assigned previously.

coordinates : array-like of float, optional

If provided, these coordinates will be written to the PDB file instead of the coordinates stored in the structure. These coordinates should line up with the atom order in the structure (not necessarily the order of the “original” PDB file if they differ)

altlocs : str, optional, default ‘all’

Keyword controlling which alternate locations are printed to the resulting PDB file. Allowable options are:

  • ‘all’ : print all alternate locations
  • ‘first’ : print only the first alternate locations
  • ‘occupancy’ : print the one with the largest occupancy. If two conformers have the same occupancy, the first one to occur is printed

Input is case-insensitive, and partial strings are permitted as long as it is a substring of one of the above options that uniquely identifies the choice.

write_anisou : bool, optional, default False

If True, an ANISOU record is written for every atom that has one. If False, ANISOU records are not written.

charmm : bool, optional, default False

If True, SEGID will be written in columns 73 to 76 of the PDB file in the typical CHARMM-style PDB output. This will be omitted for any atom that does not contain a SEGID identifier.

standard_resnames : bool, optional, default False

If True, common aliases for various amino and nucleic acid residues will be converted into the PDB-standard values.

Notes

If multiple coordinate frames are present, these will be written as separate models (but only the unit cell from the first model will be written, as the PDB standard dictates that only one set of unit cells shall be present).

write_psf(struct, dest, vmd=False)

Writes a PSF file from the stored molecule

Parameters:

struct : Structure

The Structure instance from which the PSF should be written

dest : str or file-like

The place to write the output PSF file. If it has a “write” attribute, it will be used to print the PSF file. Otherwise, it will be treated like a string and a file will be opened, printed, then closed

vmd : bool

If True, it will write out a PSF in the format that VMD prints it in (i.e., no NUMLP/NUMLPH or MOLNT sections)

Examples

>>> cs = CharmmPsfFile('testfiles/test.psf')
>>> cs.write_psf('testfiles/test2.psf')
class parmed.charmm.CharmmParameterSet(*args)[source]

Bases: parmed.parameters.ParameterSet

Stores a parameter set defined by CHARMM files. It stores the equivalent of the information found in the MASS section of the CHARMM topology file (TOP/RTF) and all of the information in the parameter files (PAR)

Parameters:

*filenames : variable length arguments of str

The list of topology, parameter, and stream files to load into the parameter set. The following file type suffixes are recognized:

.rtf, .top – Residue topology file .par, .prm – Parameter file .str – Stream file .inp – If “par” is in the file name, it is a parameter file. If

“top” is in the file name, it is a topology file. Otherwise, ValueError is raised.

Attributes

combining_rule

Methods

condense([do_dihedrals]) This function goes through each of the parameter type dicts and eliminates duplicate types.
from_parameterset(params[, copy]) Instantiates a CharmmParameterSet from another ParameterSet (or subclass).
from_structure(struct) Extracts known parameters from a Structure instance
load_set([tfile, pfile, sfiles]) Instantiates a CharmmParameterSet from a Topology file and a Parameter
read_parameter_file(pfile[, comments]) Reads all of the parameters from a parameter file.
read_stream_file(sfile) Reads RTF and PAR sections from a stream file and dispatches the
read_topology_file(tfile) Reads _only_ the atom type definitions from a topology file.
typeify_templates() Assign atom types to atom names in templates
write([top, par, str]) Write a CHARMM parameter set to a file
combining_rule
condense(do_dihedrals=True)

This function goes through each of the parameter type dicts and eliminates duplicate types. After calling this function, every unique bond, angle, dihedral, improper, or cmap type will pair with EVERY key in the type mapping dictionaries that points to the equivalent type

Parameters:

do_dihedrals : bool=True

Dihedrals can take the longest time to compress since testing their equality takes the longest (this is complicated by the existence of multi-term torsions). This flag will allow you to skip condensing the dihedral parameter types (for large parameter sets, this can cut the compression time in half)

Returns:

self

The instance that is being condensed

Notes

The return value allows you to condense the types at construction time.

classmethod from_parameterset(params, copy=False)[source]

Instantiates a CharmmParameterSet from another ParameterSet (or subclass). The main thing this feature is responsible for is converting lower-case atom type names into all upper-case and decorating the name to ensure each atom type name is unique.

Parameters:

params : parmed.parameters.ParameterSet

ParameterSet containing the list of parameters to be converted to a CHARMM-compatible set

copy : bool, optional

If True, the returned parameter set is a deep copy of params. If False, the returned parameter set is a shallow copy, and the original set may be modified if any lower-case atom type names are present. Default is False.

Returns:

new_params : CharmmParameterSet

The parameter set whose atom type names are converted to all upper-case

classmethod from_structure(struct)[source]

Extracts known parameters from a Structure instance

Parameters:

struct : parmed.structure.Structure

The parametrized Structure instance from which to extract parameters into a ParameterSet

Returns:

params : ParameterSet

The parameter set with all parameters defined in the Structure

Notes

The parameters here are copies of the ones in the Structure, so modifying the generated ParameterSet will have no effect on struct. Furthermore, the first occurrence of each parameter will be used. If future ones differ, they will be silently ignored, since this is expected behavior in some instances (like with Gromacs topologies in the ff99sb-ildn force field).

Dihedrals are a little trickier. They can be multi-term, which can be represented either as a single entry in dihedrals with a type of DihedralTypeList or multiple entries in dihedrals with a DihedralType parameter type. In this case, the parameter is constructed from either the first DihedralTypeList found or the first DihedralType of each periodicity found if no matching DihedralTypeList is found.

classmethod load_set(tfile=None, pfile=None, sfiles=None)[source]

Instantiates a CharmmParameterSet from a Topology file and a Parameter file (or just a Parameter file if it has all information)

Parameters:

tfile : str

The name of the Topology (RTF/TOP) file to parse

pfile : str

The name of the Parameter (PAR/PRM) file to parse

sfiles : list(str)

Iterable of stream (STR) file names

Returns:

New CharmmParameterSet populated with parameters found in the provided

files

Notes

The RTF file is read first (if provided), followed by the PAR file, followed by the list of stream files (in the order they are provided). Parameters in each stream file will overwrite those that came before (or simply append to the existing set if they are different)

read_parameter_file(pfile, comments=None)[source]

Reads all of the parameters from a parameter file. Versions 36 and later of the CHARMM force field files have an ATOMS section defining all of the atom types. Older versions need to load this information from the RTF/TOP files.

Parameters:

pfile : str or list of lines

Name of the CHARMM parameter file to read or list of lines to parse as a file

comments : list of str, optional

List of comments on each of the pfile lines (if pfile is a list of lines)

Notes

The atom types must all be loaded by the end of this routine. Either supply a PAR file with atom definitions in them or read in a RTF/TOP file first. Failure to do so will result in a raised RuntimeError.

read_stream_file(sfile)[source]

Reads RTF and PAR sections from a stream file and dispatches the sections to read_topology_file or read_parameter_file

Parameters:

sfile : str or CharmmStreamFile

Stream file to parse

read_topology_file(tfile)[source]

Reads _only_ the atom type definitions from a topology file. This is unnecessary for versions 36 and later of the CHARMM force field.

Parameters:

tfile : str

Name of the CHARMM topology file to read

typeify_templates()

Assign atom types to atom names in templates

write(top=None, par=None, str=None)[source]

Write a CHARMM parameter set to a file

Parameters:

top : str or file-like object, optional

If provided, the atom types will be written to this file in RTF format.

par : str or file-like object, optional

If provided, the parameters will be written to this file in PAR format. Either this or the str argument must be provided

str : str or file-like object, optional

If provided, the atom types and parameters will be written to this file as separate RTF and PAR cards that can be read as a CHARMM stream file. Either this or the par argument must be provided

Raises:

ValueError if both par and str are None

class parmed.charmm.CharmmCrdFile(fname)[source]

Bases: object

Reads and parses a CHARMM coordinate file (.crd) into its components, namely the coordinates, CHARMM atom types, resid, resname, etc.

Parameters:

fname : str

Name of the restart file to parse

Attributes

positions Atomic coordinates with units attached to them with the shape (natom, 3)
natom (int) Number of atoms in the system
resname (list of str) List of all residue names in the system
coordinates (np.ndarray with shape (1, natom, 3)) Atomic coordinates in a numpy array

Methods

id_format(filename) Identifies the file type as a CHARMM coordinate file
write(struct, dest) Writes a CHARMM coordinate file from a structure
box
coordinates
static id_format(filename)[source]

Identifies the file type as a CHARMM coordinate file

Parameters:

filename : str

Name of the file to check format for

Returns:

is_fmt : bool

True if it is a CHARMM coordinate file

positions

Atomic coordinates with units attached to them with the shape (natom, 3)

static write(struct, dest)[source]

Writes a CHARMM coordinate file from a structure

Parameters:

struct : parmed.structure.Structure

The input structure to write the CHARMM coordinate file from

dest : str or file-like object

The file name or file object to write the coordinate file to

class parmed.charmm.CharmmRstFile(fname)[source]

Bases: object

Reads and parses data, velocities and coordinates from a CHARMM restart file (.rst) of file name ‘fname’ into class attributes

Parameters:

fname : str

Name of the restart file to parse

Attributes

velocities Atomic velocities in Angstroms/picoseconds
positions Atomic positions with units
positionsold Old atomic positions with units
natom (int) Number of atoms in the system
resname (list of str) Names of all residues in the system
coordinates (np.ndarray shape(1, natom, 3)) List of all coordinates in the format [x1, y1, z1, x2, y2, z2, ...]
coordinatesold (np.ndarray shape(1, natom, 3)) List of all old coordinates in the format [x1, y1, z1, x2, y2, z2, ...]

Methods

id_format(filename) Identifies the file type as a CHARMM restart file
scan(handle, str[, r])
box
coordinates
coordinatesold
static id_format(filename)[source]

Identifies the file type as a CHARMM restart file

Parameters:

filename : str

Name of the file to check format for

Returns:

is_fmt : bool

True if it is a CHARMM restart file

positions

Atomic positions with units

positionsold

Old atomic positions with units

scan(handle, str, r=0)[source]
velocities

Atomic velocities in Angstroms/picoseconds