IMP logo
IMP Reference Guide  develop.7400db2aee,2024/11/23
The Integrative Modeling Platform
atom/charmm_forcefield.py

In this example, a PDB file is read in and scored using the CHARMM forcefield. For more control over the setup of the forcefield, see the 'charmm_forcefield_verbose.py' example.

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 
6 import IMP.atom
7 import IMP.container
8 import sys
9 
10 IMP.setup_from_argv(sys.argv, "CHARMM forcefield")
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 # 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.
34 topology.setup_hierarchy(prot)
35 
36 # Set up and evaluate the stereochemical part (bonds, angles, dihedrals,
37 # impropers) of the CHARMM forcefield
39 
40 # Add non-bonded interaction (in this case, Lennard-Jones). This needs to
41 # know the radii and well depths for each atom, so add them from the forcefield
42 # (they can also be assigned manually using the XYZR or LennardJones
43 # decorators):
44 ff.add_radii(prot)
45 ff.add_well_depths(prot)
46 
47 # Get a list of all atoms in the protein, and put it in a container
48 atoms = IMP.atom.get_by_type(prot, IMP.atom.ATOM_TYPE)
50 
51 # Add a restraint for the Lennard-Jones interaction. This is built from
52 # a collection of building blocks. First, a ClosePairContainer maintains a list
53 # of all pairs of Particles that are close. Next, all 1-2, 1-3 and 1-4 pairs
54 # from the stereochemistry created above are filtered out.
55 # Then, a LennardJonesPairScore scores a pair of atoms with the Lennard-Jones
56 # potential. Finally, a PairsRestraint is used which simply applies the
57 # LennardJonesPairScore to each pair in the ClosePairContainer.
58 nbl = IMP.container.ClosePairContainer(cont, 4.0)
59 nbl.add_pair_filter(r.get_pair_filter())
60 
61 sf = IMP.atom.ForceSwitch(6.0, 7.0)
63 restraints = [r, IMP.container.PairsRestraint(ps, nbl)]
64 scoring_function = IMP.core.RestraintsScoringFunction(restraints)
65 
66 # it gets awfully slow with internal checks
67 IMP.set_check_level(IMP.USAGE)
68 # Finally, evaluate the score of the whole system (without derivatives)
69 print(scoring_function.evaluate(False))