Merging Molecules in a Topology

When building models of molecular systems, you sometimes need to merge together pieces that come from different sources. For example, you might have a protein in one PDB file and a ligand in another PDB file. You want to combine them into a single Topology object that can be passed to ForceField.createSystem().

Let’s start by loading two PDB files.

[1]:
from openmm.app import *

pdb1 = PDBFile('villin.pdb')
pdb2 = PDBFile('ala_ala_ala.pdb')

We can now use the Modeller class to merge them together.

[2]:
modeller = Modeller(pdb1.topology, pdb1.positions)
modeller.add(pdb2.topology, pdb2.positions)
mergedTopology = modeller.topology
mergedPositions = modeller.positions

This code simply combines the two files without any concern for how the molecules are positioned relative to each other. In practice, combining molecules requires care to select their positions. This might be done by hand in a visualization program, or by a docking code, or in various other ways. It is up to you to select the positions.