Menu ▾ ▴

PredictorJars

This version refers to rev. 2333 of the predictor.jars, for older versions see history of this article

In the nmrshiftdb2 file area you can find two files, predictorc.jar and predictorh.jar, which can be used as a standalone prediction tool for c or h nmr shifts. Both jars contain an identical java class org.openscience.nmrshiftdb.PredictionTool and a csv file. The file contains all hose codes and associated shift values from nmrshiftdb2 (as of the date of the file creation of course). Together with a couple of other jars you can use this to predict shifts either by calling the predict method of the class from your java code. The jars also contain a class Test, which has a main method. On command line, the call should look like this:

java -cp predictorc.jar:cdk-interfaces.jar:cdk-io.jar:cdk-core.jar:cdk-data.jar:cdk-standard.jar:cdk-sdg.jar:cdk-valencycheck.jar:cdk-atomtype.jar:cdk-legacy.jar:cdk-smiles.jar:cdk-ctab.jar:vecmath1.2-1.14.jar:jgrapht.jar:guava-17.0.jar:beam-core-0.9.2.jar:cdk-qsaratomic.jar:cdk-qsar.jar:cdk-qsarmolecular.jar Test 10008950.mdl "Chloroform-D1 (CDCl3)"

The results gives the min, average and max values of the shifts for all carbon atoms in the mol file. using predictorh.jar will do the hydorgens. The method properly configures the molcule (see below).

Notice the following points:

  • Atom count in cdk starts with 0
  • The jars can be found in https://sourceforge.net/p/nmrshiftdb2/code/HEAD/tree/trunk/nmrshiftdb2/lib/. A cdk-all jar from cdk can also be used. cdk-1.4.19 has been tested.
  • Due to the "lego brick" nature of cdk, the HOSE code depends on the information in the molecule object. So it will look different depending on if the molecule has implicit or explicit Hs, aromaticity detected etc. cdk does not take care of this, it just uses what is there. It is the responsibility of the user to properly set up the molecule. The HOSE codes in the csv file have been generated with aromaticity detected and all explicit Hs. If you create your HOSE codes with a different setting, they will not match and the results will be unreliable.
  • The Prediction tool class is a stripped-down version of the eponymous class in the nmrshiftdb2 code. The class from nmrshiftdb2 does the same, but has additional dependencies.
  • All jars from nmrshiftdb2 repositories are compiled with Java 1.8 and need Java 1.8 to run.
  • The jars from rev. 652 use the stereo-aware prediction (if appropriate examples exist). Note that the molecules need to have 2d coordinates for this to work. If there are no 2d coordinates, the third parameter in the Predictor.predict method can be set to false to use the standard HOSE code (see example below).
  • Since the HOSE code table is kept in memory, this class needs a lot of memory depending on the size of the database. We recommand to run the JVM with at least 256 MB memory. Also remove references to the class so it can be garbage collected when no longer needed.
  • Since rev. 827 the class remembers values for HOSE codes used once and can predict atoms with the same HOSE code without doing the full lookup including sphere fallback. This can lead to better speeds. The values are remembered as long as you work with the same instance of the class.
  • Since rev. 2095 a solvent can be specified (as a parameter in the predict method of PredictionTool). Possible solvents are "Chloroform-D1 (CDCl3)", "Methanol-D4 (CD3OD)", and "Dimethylsulphoxide-D6 (DMSO-D6, C2D6SO)". The option "Unreported" will use shifts from any solvent. Notice that other solvents (although possible in nmrshiftdb2) are not part of the jars, since there is only a low number of spectra for them.

This is an example code for usage (thanks to Jean-Marc Nuzillard):

/* compile */
/* Unix: javac -classpath predictorc.jar:cdk-interfaces.jar:cdk-io.jar:cdk-core.jar:cdk-data.jar:cdk-standard.jar:cdk-sdg.jar:cdk-valencycheck.jar:cdk-atomtype.jar:cdk-legacy.jar:cdk-smiles.jar:cdk-ctab.jar:vecmath1.2-1.14.jar:jgrapht.jar:guava-17.0.jar:beam-core-1.3.3.jar:cdk-qsaratomic.jar:cdk-qsar.jar:cdk-qsarmolecular.jar Test.java */
/* Windows: javac -classpath predictorc.jar;cdk-interfaces.jar;cdk-io.jar;cdk-core.jar;cdk-data.jar;cdk-standard.jar;cdk-sdg.jar;cdk-valencycheck.jar;cdk-atomtype.jar;cdk-legacy.jar;cdk-smiles.jar;cdk-ctab.jar;vecmath1.2-1.14.jar;jgrapht.jar;guava-17.0.jar;beam-core-1.3.3.jar;cdk-qsaratomic.jar;cdk-qsar.jar;cdk-qsarmolecular.jar Test.java */

/* use */
/* Unix: java -Xmx1g -classpath predictorc.jar;cdk-interfaces.jar;cdk-io.jar;cdk-core.jar;cdk-data.jar;cdk-standard.jar;cdk-sdg.jar;cdk-valencycheck.jar;cdk-atomtype.jar;cdk-legacy.jar;cdk-smiles.jar;cdk-ctab.jar;vecmath1.2-1.14.jar;jgrapht.jar;guava-17.0.jar;beam-core-1.3.3.jar;cdk-qsaratomic.jar;cdk-qsar.jar;cdk-qsarmolecular.jar;. Test myfile.mol [solvent [no3d]] */
/* Windows: java -Xmx1g -classpath predictorc.jar;cdk-interfaces.jar;cdk-io.jar;cdk-core.jar;cdk-data.jar;cdk-standard.jar;cdk-sdg.jar;cdk-valencycheck.jar;cdk-atomtype.jar;cdk-legacy.jar;cdk-smiles.jar;cdk-ctab.jar;vecmath1.2-1.14.jar;jgrapht.jar;guava-17.0.jar;beam-core-1.3.3.jar;cdk-qsaratomic.jar;cdk-qsar.jar;cdk-qsarmolecular.jar;. Test myfile.mol [solvent [no3d]] */

/* Solvent must be "Chloroform-D1 (CDCl3)", "Methanol-D4 (CD3OD)", or "Dimethylsulphoxide-D6 (DMSO-D6, C2D6SO)" (with quotation marks)! or left unspecified

import java.io.FileReader;
import java.util.Locale;

import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.AtomContainer;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.io.MDLReader;
import org.openscience.nmrshiftdb.PredictionTool;
import org.openscience.nmrshiftdb.util.AtomUtils;

public class Test {

        public static void main(String[] args) throws Exception {
                if(args.length == 0){
/* file name as command line argument */
                        java.lang.System.exit(1);
                }
/* if there is a second argument, it must be a solvent */
                String solvent ="Unreported";
                if((args.length == 2 || args.length == 3)) {
                       solvent = args[1];
                       if(!"Chloroform-D1 (CDCl3)Methanol-D4 (CD3OD)Dimethylsulphoxide-D6 (DMSO-D6, C2D6SO)".contains(solvent)) {
                           System.out.println("solvent must be \"Chloroform-D1 (CDCl3)\", \"Methanol-D4 (CD3OD)\", or \"Dimethylsulphoxide-D6 (DMSO-D6, C2D6SO)\" (with quotation marks)!");
                           System.exit(1);
                       }
                 }
/* if third argument is no3d, we do not use extended hose code generator */
                boolean use3d = true;
                if(args.length==3 && args[2].equals("no3d"))
                    use3d=false;
/* get mol file reader (for 1 structure) from file name */
                MDLReader mdlreader = new MDLReader(new FileReader(args[0]));
/* get molecule for reader */
                IAtomContainer mol = (IAtomContainer)mdlreader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
/* !!! No explicit H in mol !!! */
/* add explicit H atoms */
                AtomUtils.addAndPlaceHydrogens(mol);
/* detect aromaticity */
                CDKHueckelAromaticityDetector.detectAromaticity(mol);
/* current atom and current result */
                float[] result;
                IAtom curAtom;
/* get predictor */
                PredictionTool predictor = new PredictionTool();
/* write header */
                System.out.println("  C    min.    mean    max.");
                System.out.println(" ---------------------------");
/* loop over atoms in mol */
                for(int i = 0 ; i < mol.getAtomCount() ; i++){
                        curAtom = mol.getAtom(i);
                        if(curAtom.getAtomicNumber() == 6) {
/* only for C atoms */
                                result = predictor.predict(mol, curAtom, use3d, solvent);
/* show result */
                                System.out.format(Locale.US, "%3d:%8.2f%8.2f%8.2f\n", i+1, result[0], result[1], result[2]);
                        }
                }
                java.lang.System.exit(0);
        }
}

Related

Wiki: AutomationInterfaces
Wiki: TechnicalTopics