Skip to content

Scripting VLifeMDS : Generating conformers of a list of molecules

by V Ganesh on September 24th, 2011

In the last post, we got a glance of scripting support in VLifeMDS. Since the last post, we have added a number of small improvements to the scripting interface, the more noticeable one being support for command line scripting in Windows. With this you will now get a consistent scripting experience across Windows and Linux.

In this current post, I will dwell more into writing some scripts that you can use for simplifying your workflow.


What functions are available?

As with Python, you can get help about any scripting functionality in VLifeMDS using the help() function:


Doing more with inbuilt Python functions

In the last post, we looked at few low level and module level functions provided by VLifeMDS. In this post, I will give example of how to combine these functions with what is already available in Python to perform batch processing.

Let us consider a typical batch processing scenario where you have a bunch of 2D .sdf files stored in a directory. You want to convert these into 3D .mol2 structures and subsequently generate conformers for each of these files.

The following listing gives an idea of how to do this using the scripting facilities in VLifeMDS.

import os
import mds
import sys
molFileFilters = ["mol2"]
def isMolFile(molFile):
  isMol = False
  for mff in molFileFilters:
      if (molFile.endswith(mff)):
         isMol = True

  return isMol

def myJob(indir, outdir)
  mds.convert2Dto3D(indir, outdir)

  molfls = os.listdir(outdir)
  nmols = len(molfls)

  for i in range(nmols):
    if (not isMolFile(molfls[i])): continue

    molFileName = os.path.join(outdir, molfls[i])
    mol = mds.readMolecule(molFileName)
    mds.generateConformer(mol, caType=0, noOfSeeds=100, FF=FF.MMFF, torsianRMS=70.0, dieleFunc=1)
# execute this script:
myJob("path/to/sdf", "path/to/mol2")

Lets walk through the above code snippet. The first three statements are imports of packages required for writing our script.  Next, we define a list of accepted file extensions ( molFileFilters ) and a function ( isMolFile() ) that checks for these given a file name. The myJob() function that follows actually does what we just stated above: convert 2D to 3D structures and the generate conformers for each.

The call mds.convert2Dto3D(indir, outdir), converts all the 2D .sdf files in the folder specified by indir to another folder outdir as .mol2 files. Next, we get a list of all the files present in folder outdir using os.listdir() function from Python. The subsequent code then iterates through each of the files, reads the molecule object, generates conformer and then finally cleans up memory for the molecule object.


How to control conformer generation?

In the listing above, the call to mds.generateConformer() does the necessary background work to generate conformers. As with the GUI for generating conformers, you have complete control over the parameters for this script function. Let us quickly run through some of the parameters used in above listing:

mds.generateConformer(mol, caType=0, noOfSeeds=100, FF=FF.MMFF, torsianRMS=70.0, dieleFunc=1)

The first argument is the molecule object returned from a call to mds.readMolecule() function. This is the only argument that is mandatory, all other arguments are optional and have some default values. Optional arguments should be provided using name=value format, as in caType=0. The following is quick description of the optional arguments used in above call:

  1. caType : VLifeMDS currently supports two methods for generating conformer : Monte-Carlo Metropolis (caType=0, default), and Systematic (caType=1) , See reference [1]
  2. noOfSeeds: If caType=0, then number of seeds used for Monte-Carlo run (default value is 50), else has no effect.
  3. FF: The force field type used to compute energy of generated conformer by Monte-Carlo as well as Systematic methods (default is FF.UFF).
  4. torsianRMS: torsian RMS cutoff used when generating conformers (default is 50.0 degrees). This parameter is used to identify geometrically similar conformers so that they can be filtered out from the final output.  A lower cutoff value would produce more conformers that are close by.
  5. dielecFunc:  use di-electric function when computing energy (default is 0, signifying false)

When the call to mds.generateConformer() completes, a .ca file with the same name as the molecule file is generated. This file can be opened using the worksheet available in VLifeMDS GUI or can be processed using a script. In later posts I will give information on how to process a .ca file using scripting.


Note on parallelization

Compute intensive functions such as mds.generateConformer() have been parallelized and automatically utilize all the cores available on multi-core processor. To get best performance, it is wise to start only one VLifeMDS instance and refrain from submitting more than one jobs simultaneously. If one starts multiple instances of VLifeMDS that all try to perform some compute intensive jobs, the overall performance will be severely hampered as all these processes try to steal CPU cycles from one another. If you have multiple jobs to be run, a better way is to create a batch of all these jobs that are run sequentially.


More to come : How to handle file types not natively supported by VLifeMDS, process .ca files etc..

[In the mean time the following are links for general information on Python scripting]

1. ‘Byte of Python’ by C. H. Swaroop available at: [External Link: ]

2. ‘Dive into Python’ available at: [External Link:]


  1. For information on Monte-Carlo Metropolis algorithm see: Metropolis, N.; Rosenbluth, A.W.; Rosenbluth, M.N.; Teller, A.H.; Teller, E. (1953). “Equations of State Calculations by Fast Computing Machines“. Journal of Chemical Physics 21 (6): 1087–1092. doi:10.1063/1.1699114

Happy scripting!

V Ganesh

I am software architect at VLife Sciences. I enjoy working with interfacing of science and technology. To know more about me drop in @ my personal blog:

More Posts - Website

From → Scripting, VLifeMDS

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS

Follow Me