The API for ParmEd Command-line Utilities¶
In some cases,
parmed interpreter is insufficient to do what you need it
to do, or perhaps you want to use some of
parmed’s functionality in your own
Python script or program.
In that case, the ParmEd API is here! Every
Action subclass is available for import from
parmed.tools. For a full listing of available actions, you are forward to
the auto-generated list in the parmed page.
Importing the actions¶
All actions can be imported from
parmed.tools with the same camelCase shown
parmed page. Examples are shown below:
>>> from parmed.tools import change, addLJType, changeRadii, tiMerge >>> from parmed.tools import setBond, deleteBond, addDihedral, addPDB
Using the actions¶
Each of the actions described on the previous page can be invoked either on a
parm list (a few, like interpolate, actually require a parm list with
multiple topologies), or a raw
object. Note that some actions do not support all
AmberParm subclasses (like those for the CHARMM or Amoeba
The first step is to instantiate the action with the
AmberParm instance as the first argument. The arguments that
each action requires in the ParmEd interpreter must then be given as separate
arguments to the constructor. Keyword arguments can optionally be given as
keyword arguments to the action constructor.
Examples of valid syntax for addLJType are shown below:
from parmed.tools import addLJType from parmed.amber import AmberParm parm = AmberParm('trx.prmtop') # All arguments separate action = addLJType(parm, "@1", "radius", 1.5, "epsilon", 0.5) # Also equivalent; keyword arguments given as keywords action = addLJType(parm, "@1", radius=1.5, epsilon=0.5)
Note that simply instantiating the object does not do anything. You need to explicitly execute it as well, as shown below (continuting from the example above):
The informational message printed to the ParmEd output are available by casting the action to a string:
print(str(action)) # Equivalent: print('%s' % action)
Note: A backwards-incompatible change was introduced after version 2.7.3 in which including all arguments as a single string in the first argument was supported. However, it was impossible to maintain this behavior and support file name paths with whitespace in them. As a result, this backwards-incompatible change was made.