IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
mutate_all_ALA.py
1# Example for: selection.mutate()
2
3# This will read a PDB file, change its sequence a little, build new
4# coordinates for any of the additional atoms using only the internal
5# geometry, and write the mutant PDB file. It can be seen as primitive
6# but rapid comparative modeling for substitution mutants. For more
7# sophisticated modeling, see http://salilab.org/modeller/wiki/Mutate%20model
8#
9# For insertion and deletion mutants, follow the standard comparative
10# modeling procedure.
11
12from modeller import Model, Alignment, Selection, Environ
13import sys
14import os
15
16
17def mutate_all_ALA(code):
18 env = Environ()
19 env.io.atom_files_directory = ['../atom_files']
20
21 # Read the topology library with non-hydrogen atoms only:
22 env.libs.topology.read(file='$(LIB)/top_heav.lib')
23 # To produce a mutant with all hydrogens, uncomment this line:
24 # env.libs.topology.read(file='$(LIB)/top_allh.lib')
25
26 # Read the CHARMM parameter library:
27 env.libs.parameters.read(file='$(LIB)/par.lib')
28
29 # Read the original PDB file and copy its sequence to the alignment array:
30 # pdbpath = sys.argv[1]
31 aln = Alignment(env)
32 mdl = Model(env, file=code)
33 mdl2 = Model(env, file=code)
34 aln.append_model(mdl, atom_files=code, align_codes=code)
35
36 # Select the residues to be mutated: in this case all ASP residues:
37 # sel = selection(mdl).only_residue_types('ASP')
38 sel = Selection(mdl)
39
40 # The second example is commented out; it selects residues '1' and '10'.
41 # sel = selection(mdl.residues['1'], mdl.residues['10'])
42
43 # Mutate the selected residues into HIS residues (neutral HIS):
44 sel.mutate(residue_type='ALA')
45
46 # Add the mutated sequence to the alignment arrays (it is now the second
47 # sequence in the alignment):
48 aln.append_model(mdl, align_codes='1fas-1')
49
50 # Generate molecular topology for the mutant:
51 mdl.clear_topology()
52 mdl.generate_topology(aln['1fas-1'])
53
54 # Transfer all the coordinates you can from the template native structure
55 # to the mutant (this works even if the order of atoms in the native PDB
56 # file is not standard):
57 mdl.transfer_xyz(aln)
58
59 # Build the remaining unknown coordinates for the mutant:
60 mdl.build(initialize_xyz=False, build_method='INTERNAL_COORDINATES')
61 mdl.res_num_from(mdl2, aln)
62 # Write the mutant to a file:
63 print(code)
64 new_code = os.path.basename(code).split('.')[0]
65 mdl.write(file=new_code+'_m.pdb', no_ter=True)
66
67
68if __name__ == "__main__":
69 pdbpath = sys.argv[1]
70 mutate_all_ALA(pdbpath)
71 print("Done mutation from the main file")