IMP logo
IMP Reference Guide  2.15.0
The Integrative Modeling Platform
charmm_forcefield_verbose.py
1 ## \example atom/charmm_forcefield_verbose.py
2 # In this example, a PDB file is read in and scored using the CHARMM forcefield. It is similar to the 'charmm_forcefield.py' example, but fully works through each step of the procedure using lower-level IMP classes. This is useful if you want to customize the way in which the forcefield is applied.
3 #
4 
5 from __future__ import print_function
6 import IMP.atom
7 import IMP.container
8 import sys
9 
10 IMP.setup_from_argv(sys.argv, "CHARMM forcefield verbose")
11 
12 # Create an IMP model and add a heavy atom-only protein from a PDB file
13 m = IMP.Model()
14 prot = 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
22 topology = 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.
27 topology.apply_default_patches()
28 
29 # Each atom is mapped to its CHARMM type. These are needed to look up bond
30 # lengths, Lennard-Jones radii etc. in the CHARMM parameter file. Atom types
31 # can also be manually assigned at this point using the CHARMMAtom decorator.
32 topology.add_atom_types(prot)
33 
34 # Remove any atoms that are in the PDB file but not in the topology, and add
35 # in any that are in the topology but not the PDB.
37 topology.add_missing_atoms(prot)
38 
39 # Construct Cartesian coordinates for any atoms that were added
40 topology.add_coordinates(prot)
41 
42 # Generate and return lists of bonds, angles, dihedrals and impropers for
43 # the protein. Each is a Particle in the model which defines the 2, 3 or 4
44 # atoms that are bonded, and adds parameters such as ideal bond length
45 # and force constant. Note that bonds and impropers are explicitly listed
46 # in the CHARMM topology file, while angles and dihedrals are generated
47 # automatically from an existing set of bonds. These particles only define the
48 # bonds, but do not score them or exclude them from the nonbonded list.
49 bonds = topology.add_bonds(prot)
50 angles = ff.create_angles(bonds)
51 dihedrals = ff.create_dihedrals(bonds)
52 impropers = topology.add_impropers(prot)
53 
54 # Maintain stereochemistry by scoring bonds, angles, dihedrals and impropers
55 
56 # Score all of the bonds. This is done by combining IMP 'building blocks':
57 # - A ListSingletonContainer simply manages a list of the bond particles.
58 # - A BondSingletonScore, when given a bond particle, scores the bond by
59 # calculating the distance between the two atoms it bonds, subtracting the
60 # ideal value, and weighting the result by the bond's "stiffness", such that
61 # an "ideal" bond scores zero, and bonds away from equilibrium score non-zero.
62 # It then hands off to a UnaryFunction to actually penalize the value. In
63 # this case, a Harmonic UnaryFunction is used with a mean of zero, so that
64 # bond lengths are harmonically restrained.
65 # - A SingletonsRestraint simply goes through each of the bonds in the
66 # container and scores each one in turn.
67 cont = IMP.container.ListSingletonContainer(m, bonds, "bonds")
69 r = IMP.container.SingletonsRestraint(bss, cont, "bonds")
70 rs = [r]
71 
72 # Score angles, dihedrals, and impropers. In the CHARMM forcefield, angles and
73 # impropers are harmonically restrained, so this is the same as for bonds.
74 # Dihedrals are scored internally by a periodic (cosine) function.
75 cont = IMP.container.ListSingletonContainer(m, angles, "angles")
77 r = IMP.container.SingletonsRestraint(bss, cont, "angles")
78 rs.append(r)
79 
80 cont = IMP.container.ListSingletonContainer(m, dihedrals, "dihedrals")
82 r = IMP.container.SingletonsRestraint(bss, cont, "dihedrals")
83 rs.append(r)
84 
85 cont = IMP.container.ListSingletonContainer(m, impropers, "impropers")
87 rs.append(IMP.container.SingletonsRestraint(bss, cont, "improppers"))
88 
89 # Add non-bonded interaction (in this case, Lennard-Jones). This needs to
90 # know the radii and well depths for each atom, so add them from the forcefield
91 # (they can also be assigned manually using the XYZR or LennardJones
92 # decorators):
93 ff.add_radii(prot)
94 ff.add_well_depths(prot)
95 
96 # Get a list of all atoms in the protein, and put it in a container
97 atoms = IMP.atom.get_by_type(prot, IMP.atom.ATOM_TYPE)
99 
100 # Add a restraint for the Lennard-Jones interaction. Again, this is built from
101 # a collection of building blocks. First, a ClosePairContainer maintains a list
102 # of all pairs of Particles that are close. A StereochemistryPairFilter is used
103 # to exclude atoms from this list that are bonded to each other or are involved
104 # in an angle or dihedral (1-3 or 1-4 interaction). Then, a
105 # LennardJonesPairScore scores a pair of atoms with the Lennard-Jones potential.
106 # Finally, a PairsRestraint is used which simply applies the
107 # LennardJonesPairScore to each pair in the ClosePairContainer.
108 nbl = IMP.container.ClosePairContainer(cont, 4.0)
110 pair_filter.set_bonds(bonds)
111 pair_filter.set_angles(angles)
112 pair_filter.set_dihedrals(dihedrals)
113 nbl.add_pair_filter(pair_filter)
114 
115 sf = IMP.atom.ForceSwitch(6.0, 7.0)
117 rs.append(IMP.container.PairsRestraint(ps, nbl))
118 
119 score_func = IMP.core.RestraintsScoringFunction(rs)
120 
121 # it gets awfully slow with internal checks
122 IMP.set_check_level(IMP.USAGE)
123 
124 # Finally, evaluate the score of the whole system (without derivatives)
125 print(score_func.evaluate(False))
Applies a SingletonScore to each Singleton in a list.
Select non water and non hydrogen atoms.
Definition: pdb.h:245
CHARMMParameters * get_heavy_atom_CHARMM_parameters()
Score the angle based on a UnaryFunction,.
void remove_charmm_untyped_atoms(Hierarchy hierarchy)
Remove any atom from the Hierarchy that does not have a CHARMM type.
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
Various classes to hold sets of particles.
std::string get_example_path(std::string file_name)
Return the full path to one of this module's example files.
Create a scoring function on a list of restraints.
Return all close unordered pairs of particles taken from the SingletonContainer.
void read_pdb(TextInput input, int model, Hierarchy h)
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Lennard-Jones score between a pair of particles.
Store a list of ParticleIndexes.
Score the improper dihedral based on a UnaryFunction,.
Score the bond based on a UnaryFunction,.
A filter that excludes bonds, angles and dihedrals.
Smooth interaction scores by switching the derivatives (force switch).
Functionality for loading, creating, manipulating and scoring atomic structures.
Applies a PairScore to each Pair in a list.
void set_check_level(CheckLevel tf)
Control runtime checks in the code.
Definition: exception.h:73
Harmonic function (symmetric about the mean)
Definition: core/Harmonic.h:24