IMP  2.1.1
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 import IMP.atom
6 import IMP.container
7 
8 # Create an IMP model and add a heavy atom-only protein from a PDB file
10 prot = IMP.atom.read_pdb(IMP.atom.get_example_path("example_protein.pdb"), m,
12 
13 # Read in the CHARMM heavy atom topology and parameter files
15 
16 # Using the CHARMM libraries, determine the ideal topology (atoms and their
17 # connectivity) for the PDB file's primary sequence
18 topology = ff.create_topology(prot)
19 
20 # Typically this modifies the C and N termini of each chain in the protein by
21 # applying the CHARMM CTER and NTER patches. Patches can also be manually
22 # applied at this point, e.g. to add disulfide bridges.
23 topology.apply_default_patches()
24 
25 # Each atom is mapped to its CHARMM type. These are needed to look up bond
26 # lengths, Lennard-Jones radii etc. in the CHARMM parameter file. Atom types
27 # can also be manually assigned at this point using the CHARMMAtom decorator.
28 topology.add_atom_types(prot)
29 
30 # Remove any atoms that are in the PDB file but not in the topology, and add
31 # in any that are in the topology but not the PDB.
33 topology.add_missing_atoms(prot)
34 
35 # Construct Cartesian coordinates for any atoms that were added
36 topology.add_coordinates(prot)
37 
38 # Generate and return lists of bonds, angles, dihedrals and impropers for
39 # the protein. Each is a Particle in the model which defines the 2, 3 or 4
40 # atoms that are bonded, and adds parameters such as ideal bond length
41 # and force constant. Note that bonds and impropers are explicitly listed
42 # in the CHARMM topology file, while angles and dihedrals are generated
43 # automatically from an existing set of bonds. These particles only define the
44 # bonds, but do not score them or exclude them from the nonbonded list.
45 bonds = topology.add_bonds(prot)
46 angles = ff.create_angles(bonds)
47 dihedrals = ff.create_dihedrals(bonds)
48 impropers = topology.add_impropers(prot)
49 
50 # Maintain stereochemistry by scoring bonds, angles, dihedrals and impropers
51 
52 # Score all of the bonds. This is done by combining IMP 'building blocks':
53 # - A ListSingletonContainer simply manages a list of the bond particles.
54 # - A BondSingletonScore, when given a bond particle, scores the bond by
55 # calculating the distance between the two atoms it bonds, subtracting the
56 # ideal value, and weighting the result by the bond's "stiffness", such that
57 # an "ideal" bond scores zero, and bonds away from equilibrium score non-zero.
58 # It then hands off to a UnaryFunction to actually penalize the value. In
59 # this case, a Harmonic UnaryFunction is used with a mean of zero, so that
60 # bond lengths are harmonically restrained.
61 # - A SingletonsRestraint simply goes through each of the bonds in the
62 # container and scores each one in turn.
63 cont = IMP.container.ListSingletonContainer(bonds, "bonds")
65 r = IMP.container.SingletonsRestraint(bss, cont, "bonds")
66 m.add_restraint(r)
67 
68 # Score angles, dihedrals, and impropers. In the CHARMM forcefield, angles and
69 # impropers are harmonically restrained, so this is the same as for bonds.
70 # Dihedrals are scored internally by a periodic (cosine) function.
71 cont = IMP.container.ListSingletonContainer(angles, "angles")
73 r = IMP.container.SingletonsRestraint(bss, cont, "angles")
74 m.add_restraint(r)
75 
76 cont = IMP.container.ListSingletonContainer(dihedrals, "dihedrals")
78 r = IMP.container.SingletonsRestraint(bss, cont, "dihedrals")
79 m.add_restraint(r)
80 
81 cont = IMP.container.ListSingletonContainer(impropers, "impropers")
83 m.add_restraint(IMP.container.SingletonsRestraint(bss, cont, "improppers"))
84 
85 # Add non-bonded interaction (in this case, Lennard-Jones). This needs to
86 # know the radii and well depths for each atom, so add them from the forcefield
87 # (they can also be assigned manually using the XYZR or LennardJones
88 # decorators):
89 ff.add_radii(prot)
90 ff.add_well_depths(prot)
91 
92 # Get a list of all atoms in the protein, and put it in a container
93 atoms = IMP.atom.get_by_type(prot, IMP.atom.ATOM_TYPE)
95 
96 # Add a restraint for the Lennard-Jones interaction. Again, this is built from
97 # a collection of building blocks. First, a ClosePairContainer maintains a list
98 # of all pairs of Particles that are close. A StereochemistryPairFilter is used
99 # to exclude atoms from this list that are bonded to each other or are involved
100 # in an angle or dihedral (1-3 or 1-4 interaction). Then, a
101 # LennardJonesPairScore scores a pair of atoms with the Lennard-Jones potential.
102 # Finally, a PairsRestraint is used which simply applies the
103 # LennardJonesPairScore to each pair in the ClosePairContainer.
104 nbl = IMP.container.ClosePairContainer(cont, 4.0)
106 pair_filter.set_bonds(bonds)
107 pair_filter.set_angles(angles)
108 pair_filter.set_dihedrals(dihedrals)
109 nbl.add_pair_filter(pair_filter)
110 
111 sf = IMP.atom.ForceSwitch(6.0, 7.0)
113 m.add_restraint(IMP.container.PairsRestraint(ps, nbl))
114 
115 # it gets awfully slow with internal checks
116 IMP.base.set_check_level(IMP.base.USAGE)
117 
118 # Finally, evaluate the score of the whole system (without derivatives)
119 print m.evaluate(False)
Applies a SingletonScore to each Singleton in a list.
Select non water and non hydrogen atoms.
Definition: pdb.h:198
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.
See IMP.container for more information.
void set_check_level(CheckLevel tf)
Control runtime checks in the code.
std::string get_example_path(std::string file_name)
Return the path to installed example data for this module.
Return all close unordered pairs of particles taken from the SingletonContainer.
Lennard-Jones score between a pair of particles.
Hierarchies get_by_type(Hierarchy mhd, GetByType t)
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).
See IMP.atom for more information.
void read_pdb(base::TextInput input, int model, Hierarchy h)
Applies a PairScore to each Pair in a list.
Class for storing model, its restraints, constraints, and particles.
Harmonic function (symmetric about the mean)
Definition: core/Harmonic.h:25