Refining only part of the model

The AutoModel class contains a AutoModel.select_atoms() function which selects the atoms to be moved during optimization. By default, the routine selects all atoms, but you can redefine it to select any subset of atoms, and then only those atoms will be refined. (To redefine the routine, it is necessary to create a ‘subclass’ of AutoModel, here called MyModel, which has the modified routine within it. We then use MyModel in place of AutoModel. The select_atoms routine should return a Selection object; see Section 6.9 for further information.)

In this particular case, we use the Model.residue_range() function to select residues 1 and 2 from the first (A) chain. See Section 6.17.9 for ways to specify residues, and Selection() for other examples of selecting atoms or residues. Please note that the residue numbers and chain IDs refer to the built model, not to the template(s). This is because template PDB residue numbering can be inconsistent, and in the case where you have two or more templates, residues from different parts of the sequence coming from different templates could have the same number. MODELLER always names the model residues consistently, counting up from 1. Chain IDs A, B, C, etc are assigned2.2. If in doubt about residue numbering, first build a model using the simple script in section 2.1, and then look at the final model (or the initial unoptimized .ini model) for the residue numbering.

By default, the selected atoms will “feel” the presence of other atoms via all the static and possibly dynamic restraints that include both selected and un-selected atoms. However, you can turn off dynamic interactions between the selected and unselected regions by setting EnergyData.nonbonded_sel_atoms to 2 (by default it is 1).

The difference between this script and the one for loop modeling is that here the selected regions are optimized with the default optimization protocol and the default restraints, which generally include template-derived restraints. In contrast, the loop modeling routine does not use template-dependent restraints, but does a much more thorough optimization.

Example: examples/automodel/model-segment.py

# Comparative modeling by the AutoModel class
#
# Demonstrates how to refine only a part of the model.
#
# You may want to use the more exhaustive "loop" modeling routines instead.
#
from modeller import *
from modeller.automodel import *    # Load the AutoModel class

log.verbose()

# Override the 'select_atoms' routine in the 'AutoModel' class:
# (To build an all-hydrogen model, derive from AllHModel rather than AutoModel
# here.)
class MyModel(AutoModel):
    def select_atoms(self):
        # Select residues 1 and 2 in chain A (PDB numbering)
        return Selection(self.residue_range('1:A', '2:A'))

        # Residues 4, 6, 10 in chain A:
        # return Selection(self.residues['4:A'], self.residues['6:A'],
        #                  self.residues['10:A'])

        # All residues except 1-5 in chain A:
        # return Selection(self) - Selection(self.residue_range('1:A', '5:A'))


env = Environ()
# directories for input atom files
env.io.atom_files_directory = ['.', '../atom_files']
# selected atoms do not feel the neighborhood
env.edat.nonbonded_sel_atoms = 2

# Be sure to use 'MyModel' rather than 'AutoModel' here!
a = MyModel(env,
            alnfile  = 'alignment.ali',     # alignment filename
            knowns   = '5fd1',              # codes of the templates
            sequence = '1fdx')              # code of the target

a.starting_model= 3                # index of the first model
a.ending_model  = 3                # index of the last model
                                   # (determines how many models to calculate)
a.make()                           # do comparative modeling