IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
charmm_forcefield.py
1## \example atom/charmm_forcefield.py
2# In this example, a PDB file is read in and scored using the CHARMM
3# forcefield. For more control over the setup of the forcefield, see
4# the 'charmm_forcefield_verbose.py' example.
5
6import IMP.atom
7import IMP.container
8import sys
9
10IMP.setup_from_argv(sys.argv, "CHARMM forcefield")
11
12# Create an IMP model and add a heavy atom-only protein from a PDB file
13m = IMP.Model()
14prot = IMP.atom.read_pdb(IMP.atom.get_example_path("example_protein.pdb"), m,
16
17# Read in the CHARMM heavy atom topology and parameter files
19
20# Using the CHARMM libraries, determine the ideal topology (atoms and their
21# connectivity) for the PDB file's primary sequence
22topology = ff.create_topology(prot)
23
24# Typically this modifies the C and N termini of each chain in the protein by
25# applying the CHARMM CTER and NTER patches. Patches can also be manually
26# applied at this point, e.g. to add disulfide bridges.
27topology.apply_default_patches()
28
29# Make the PDB file conform with the topology; i.e. if it contains extra
30# atoms that are not in the CHARMM topology file, remove them; if it is
31# missing atoms (e.g. sidechains, hydrogens) that are in the CHARMM topology,
32# add them and construct their Cartesian coordinates from internal coordinate
33# information.
34topology.setup_hierarchy(prot)
35
36# Set up and evaluate the stereochemical part (bonds, angles, dihedrals,
37# impropers) of the CHARMM forcefield
39
40# Add radii from the forcefield, used for close pairs calculation
41ff.add_radii(prot)
42
43# Add non-bonded interaction (in this case, Lennard-Jones). This needs to
44# know the Lennard-Jones types for all atoms (which in turn define the radius
45# and well depth), so add them from the forcefield (they can also be assigned
46# manually using the LennardJonesType decorator):
47ff.add_lennard_jones_types(prot)
48
49# Get a list of all atoms in the protein, and put it in a container
50atoms = IMP.atom.get_by_type(prot, IMP.atom.ATOM_TYPE)
52
53# Add a restraint for the Lennard-Jones interaction. This is built from
54# a collection of building blocks. First, a ClosePairContainer maintains a list
55# of all pairs of Particles that are close. Next, all 1-2, 1-3 and 1-4 pairs
56# from the stereochemistry created above are filtered out.
57# Then, a LennardJonesTypedPairScore scores a pair of atoms with the
58# Lennard-Jones potential, using the Lennard-Jones types already assigned.
59# Finally, a PairsRestraint is used which simply applies the
60# LennardJonesTypedPairScore to each pair in the ClosePairContainer.
62nbl.add_pair_filter(r.get_pair_filter())
63
64sf = IMP.atom.ForceSwitch(6.0, 7.0)
66restraints = [r, IMP.container.PairsRestraint(ps, nbl)]
67scoring_function = IMP.core.RestraintsScoringFunction(restraints)
68
69# it gets awfully slow with internal checks
70IMP.set_check_level(IMP.USAGE)
71# Finally, evaluate the score of the whole system (without derivatives)
72print(scoring_function.evaluate(False))
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Enforce CHARMM stereochemistry on the given Hierarchy.
Smooth interaction scores by switching the derivatives (force switch).
Hierarchies get_by_type(Hierarchy mhd, GetByType t)
Gather all the molecular particles of a certain level in the hierarchy.
Lennard-Jones score between a pair of particles.
Select non water and non hydrogen atoms.
Definition pdb.h:320
Return all close unordered pairs of particles taken from the SingletonContainer.
Applies a PairScore to each Pair in a list.
Create a scoring function on a list of restraints.
Functionality for loading, creating, manipulating and scoring atomic structures.
std::string get_example_path(std::string file_name)
Return the full path to one of this module's example files.
CHARMMParameters * get_heavy_atom_CHARMM_parameters()
Hierarchy read_pdb(TextInput input, Model *model, PDBSelector *selector=get_default_pdb_selector(), bool select_first_model=true)
Read all the molecules in the first model of the PDB file.
Various classes to hold sets of particles.
void set_check_level(CheckLevel tf)
Control runtime checks in the code.
Definition exception.h:72
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.