Skip to content

Topo

Provides a class for generating Amber topology and coordinate files using the tleap program.

This module defines the AmberTopoGen class, which inherits from simlify.simulation.topo.TopoGen. It implements the logic to create input files for tleap, execute tleap, and parse its output to generate Amber topology (.prmtop) and coordinate (.inpcrd) files. It also handles the loading of force fields, solvation, and ion addition based on the provided SimlifyConfig.

FF_WATER_SOLVENT_BOX_MAP = {'tip3p': 'TIP3PBOX', 'tip4p': 'TIP4PBOX', 'tip4pew': 'TIP4PEWBOX', 'tip5p': 'TIP5PBOX', 'opc': 'OPCBOX', 'opc3': 'OPC3BOX', 'pol3': 'POL3BOX', 'spce': 'SPCBOX'}

Maps ff_water in simulation contexts to tleap box types.

TLEAP_PATH = os.environ.get('TLEAP_PATH', 'tleap')

Path to tleap executable.

You can specify this by setting the path to the TLEAP_PATH environmental variable. For example:

export TLEAP_PATH="~/miniconda3/envs/metalflare-dev/bin/tleap

AmberTopoGen()

Bases: TopoGen

Standardized framework for generating topology files for Amber simulations using tleap.

dry_run(path_structure, simlify_config, **kwargs)

Performs a dry run of tleap to obtain preliminary information about the system.

This method executes tleap with a minimal input script that loads the structure, solvates it, saves a temporary PDB file, and calculates the total charge. The output log is then parsed to extract information such as box dimensions, volume, mass, density, the number of solvent molecules, and the net charge. This information is then used to determine the number of ions needed to neutralize the system or achieve a desired ionic concentration.

PARAMETER DESCRIPTION
path_structure

Path to the structure file (must be a PDB file for Amber).

TYPE: str

simlify_config

Simlify configuration object.

TYPE: SimlifyConfig

RETURNS DESCRIPTION
dict[str, Any]

A dictionary containing keyword arguments to be passed into the run method. This dictionary includes information about the number of anions and cations required for the system.

Examples:

The base tleap input file generated for a dry run with standard Amber protein context might look like this:

source leaprc.protein.ff19SB
source leaprc.water.opc3
# User-defined lines from simlify_config.topology.append_lines would be here
mol = loadpdb <path_structure>
solvatebox mol OPC3BOX 10.0
savepdb mol <temporary_file>.pdb
charge mol
quit

ff_lines(simlify_config)

Prepares tleap commands to load specified force fields.

This method generates a list of source leaprc. commands for tleap based on the force field settings in the provided SimlifyConfig. It checks for the presence of protein, water, DNA, RNA, GLYCAM, lipid, small molecule, and ion force fields in the configuration and creates the corresponding source or loadAmberParams commands.

PARAMETER DESCRIPTION
simlify_config

A SimlifyConfig object containing the simulation context and force field settings.

TYPE: SimlifyConfig

RETURNS DESCRIPTION
Iterable[str]

list of strings, where each string is a tleap

command to load a specific force field.

Examples:

>>> from simlify import SimlifyConfig
>>> config = SimlifyConfig(
...     engine={
...         "ff": {
...             "protein": "ff14SB",
...             "water": "tip3p",
...             "small_molecule": "gaff2",
...         }
...     }
... )
>>> list(AmberTopoGen.ff_lines(config))
['source leaprc.protein.ff14SB', 'source leaprc.water.tip3p', 'source leaprc.gaff2']

run(path_structure, simlify_config, charge_anion_num=0, charge_cation_num=0, path_tleap_pdb=None, **kwargs)

Runs tleap to generate Amber topology and coordinate files for the system.

This method takes the path to the structure file, the SimlifyConfig object, and keyword arguments (typically obtained from the dry_run method) to generate the final tleap input script. It adds ions to neutralize the system or achieve a desired concentration, solvates the system, and then saves the Amber topology (.prmtop) and coordinate (.inpcrd) files to the specified output paths.

PARAMETER DESCRIPTION
path_structure

Path to the structure file (must be a PDB file for Amber).

TYPE: str

simlify_config

Simlify configuration object.

TYPE: SimlifyConfig

charge_anion_num

The number of anions to add.

TYPE: int DEFAULT: 0

charge_cation_num

The number of cations to add.

TYPE: int DEFAULT: 0

path_tleap_pdb

Specify the path to the prepared system as a PDB file after tleap is finished. If not provided, a temporary file is used.

TYPE: None | str DEFAULT: None

RETURNS DESCRIPTION
dict[str, Any]

A dictionary containing information parsed from the tleap log file.