D.2. mychemdb-manager.py

The mychemdb-manager.py script can be found in the scripts directory. It is a Python program released under the new BSD license. It requires the MySQLdb module. This module can be retrieved from the Mysql-Python Project Web Page.

The usage of the script is simple. A help can be displayed by using the -h option:

# python mychemdb_manager.py -h
Usage: mychemdb_manager.py [options] FILE

mychemdb_manager.py load a file in MDL SDF format into a MySQL database and
creates a chemical cartridge with Mychem.

  --version       show program's version number and exit
  -h, --help      show this help message and exit
  -H HOST         connect to host [default: localhost]
  -U USER         user for login to MySQL [default: mychem]
  -P              use a password to connect to MySQL (it will be asked from
                  the tty)
  -D DB           database to use [default: mychem]
  -n NAMETAG      name tag to use in the MDL SDF file
  -l LOGFILE      log file name
  -t TABLEPREFIX  table prefix
  -a              append data if the compound table exists
  -r              replace data if the compound table exists
  -u              update data if the compound table exists
  -v              verbose mode

The first step is to create a database for storing the chemical tables. By default, the script will use mychem, but an other database name can be selected by using the -D option.

-- Database creation


Once the database is created, it is possible to load the MDL SDF file with the mychem-manager.py script:

# python mychem-manager.py -D mychem -U user -P database.sdf
Enter MySQL password:
The MDL SDFFile has been successfully loaded.

The previous command will create the following tables:


It is possible to add a prefix to the name of the tables by using the -t option.

If all these tables already exist, the script will ask about the action to perform:

In case only one, two or three tables exist, the update option will not be available. It it possible to avoid this prompt by using the -a (append), -r (replace) or -u (update) option when calling the program.