7.3. Example 03: Utilizing Step Modifications

This example demonstrates how to use the FreeLigand class to perform a multi-state RESP calculation, with modifications made to the steps in the pipeline. This tutorial shows briefly how to add, remove, and insert stages into the pipeline, starting from a pre-initialized pipeline.

7.3.1. Learning Outcomes:

  1. Learn how top modify existing pipeline recipes by adding, removing, and inserting stages.

7.3.2. Files

The files for this example can be found in the LigandParameterization/examples/03_ModifySteps directory of the source code.

7.3.3. Tutorial

In this example, we will demonstrate how to take an existing recipe, such as ModifySteps, and then modify the stages in the pipeline. This can also be used to create a fully new pipeline by subclassing the Parameterization class and adding your own stages.

As always, the first step is to import the module, load the pdb file into the recipe of your choosing, and use the setup method and list_stages method to add the stages to the pipeline, and print them to the screen.

import sys
from pathlib import Path

# Import the module
from ligandparam.recipes import LazyLigand
from ligandparam.stages import StageNormalizeCharge

# Environment variables for Gaussian. If your environment is already set up, you can ignore this.
gaussian_paths = {
    "gaussian_root": "/home/.../GAUSSIAN",
    "gauss_exedir": "/home/.../GAUSSIAN/g16/bsd:/home/.../GAUSSIAN/g16",
    "gaussian_binary": "/home/.../GAUSSIAN/g16/g16",
    "gaussian_scratch": "/home/.../GAUSSIAN/g16/scratch",
}

cwd = Path(sys.argv[0]).resolve().parent

# Load the pdb as a instance of the FreeLigand class
test = LazyLigand(
    in_filename=cwd / "thiophenol.pdb",
    cwd=cwd,
    net_charge=0,
    atom_type="gaff2",
    logger="stream",
    # antechamber will name your residue 'MOL' by default, and we follow that standard by default,
    # so you probably want to set it yourself:
    molname="LIG",
    # **gaussian_paths,
)

# Select the pre-initialized stages for Lazy Ligand
test.setup()

# List the stages out to the user
test.list_stages()

Now, unlike before, we are going to remove the Normalize1 stage from the pipeline. If you recall, the Normalize1 stage occurs after the Initialize stage and before the Minimize stage.

test.remove_stage("Normalize1")

Running this command removes Normalize1 from the pipeline, and the pipeline will now skip this stage when it is executed (if you use execute).

Stages can also be added to the pipeline:

test.insert_stage(
    StageNormalizeCharge("mynormalization", main_input="thiophenol.initial.mol2", cwd=cwd, net_charge=0,
                         out_mol2="thiophenol.initial.mol2"),
    "MinimizeLowTheory",

Adding stages to the pipeline adds them before the specified stage, so we added mynormalization before the MinimizeLowTheory stage.

Finally, the pipeline can be executed using the execute method as before.


test.list_stages()

test.execute(nproc=12, mem="8")

7.3.4. Full code

import sys
from pathlib import Path

# Import the module
from ligandparam.recipes import LazyLigand
from ligandparam.stages import StageNormalizeCharge

# Environment variables for Gaussian. If your environment is already set up, you can ignore this.
gaussian_paths = {
    "gaussian_root": "/home/.../GAUSSIAN",
    "gauss_exedir": "/home/.../GAUSSIAN/g16/bsd:/home/.../GAUSSIAN/g16",
    "gaussian_binary": "/home/.../GAUSSIAN/g16/g16",
    "gaussian_scratch": "/home/.../GAUSSIAN/g16/scratch",
}

cwd = Path(sys.argv[0]).resolve().parent

# Load the pdb as a instance of the FreeLigand class
test = LazyLigand(
    in_filename=cwd / "thiophenol.pdb",
    cwd=cwd,
    net_charge=0,
    atom_type="gaff2",
    logger="stream",
    # antechamber will name your residue 'MOL' by default, and we follow that standard by default,
    # so you probably want to set it yourself:
    molname="LIG",
    # **gaussian_paths,
)

# Select the pre-initialized stages for Lazy Ligand
test.setup()

# List the stages out to the user
test.list_stages()

test.remove_stage("Normalize1")

test.insert_stage(
    StageNormalizeCharge("mynormalization", main_input="thiophenol.initial.mol2", cwd=cwd, net_charge=0,
                         out_mol2="thiophenol.initial.mol2"),
    "MinimizeLowTheory",
)

# List the stages after inserting.

test.list_stages()

test.execute(nproc=12, mem="8")