Chemaxon Java classes from Matlab

User 99e51048d1

31-08-2011 12:15:12

Dear all


I'm now interested in using the java class ''. I haven't used Java classes before. I'm working in MatLab from where it is possible to use third-party Java classes. But first, the class should be made available to MatLab. To do so, they recommend:


"To access one or more classes belonging to a package, you need to make the entire package available to MATLAB. Do this by adding to classpath.txt the full path to the parent directory of the highest-level directory of the package path. This directory is the first component in the package name.

For example, if your Java class package has its classes in directory d:\work\com\mw\tbx\ini, add the following entry to your classpath.txt, 'd:\work'"



I have looked for the corresponding directory in the case of '' but I found nothing. I have installed JChem (jchem-


Can you give me a hint?


Thanks in advance.

ChemAxon e274e1bada

31-08-2011 13:16:46

I have moved this topic to the appropriate forum. The experts will respond soon.

User 99e51048d1

31-08-2011 13:40:07

Thanks ebuki, I will be looking forward.

ChemAxon 4a2fc68cd1

31-08-2011 18:51:51


According to the description you sent, you would require the ChemAxon class files located in a directory. In an installed JChem, these class files are located in .jar files, from which they can be extracted. To do this, follow these steps:

  1. Locate the JChem install directory on your hard disk. By default, it is c:\Program Files\ChemAxon\JChem.

  2. Create a directory to which you would like to copy ChemAxon class files. E.g. c:\work\chemaxon\classes.

  3. Start a command prompt and enter the following commands:

    cd c:\work\chemaxon\classes
    FOR /f %i IN ('dir /b
    "c:\Program Files\ChemAxon\JChem\lib\*.jar"') do jar xf "c:\Program Files\ChemAxon\JChem\lib\%i"

    These commands copy all class files into c:\work\chemaxon\classes. It would take some time.

  4. Open MatLab's classpath.txt in an editor and add a new line containing c:\work\chemaxon\classes to it.

  5. Restart MatLab.

These steps should allow ChemAxon classes in your MatLab. Try it with entering e.g. the following expression:


You should get ans=6 as a reply. (As far as I understand the usage of JAVA classes inside MatLab, but I have never tried it.)

Once you can use ChemAxon classes in MatLab, I can give you further instructions on the usage of MCES.


User 99e51048d1

01-09-2011 08:59:10

Thanks a lot Peter.

I tried your suggestion but the jar command did not work in my machine

'jar' is not recognized as an in
operable program or batch file.

However, the .jar files you pointed to can be feed into MatLab without unpacking them. The explanation is here under 'Making Classes in a JAR File Available'. I did what they say and then tried the command

>> chemaxon.formats.MolImporter.importMol("C1C(=O)CCC1").getAtomCount()
Error: The input character is not valid in MATLAB statements or expressions.

and it fails as well as the MatLab version with single quotes,

>> chemaxon.formats.MolImporter.importMol('C1C(=O)CCC1').getAtomCount()
??? No method 'importMol' with matching signature found for class 'chemaxon.formats.MolImporter'.

But then,

>> inst = chemaxon.formats.MolImporter;
>> which importMol
importMol is a Java method  % chemaxon.formats.MolImporter method
>> methods('chemaxon.formats.MolImporter')

Methods for class chemaxon.formats.MolImporter:

MolImporter                            getMoleculeIterator          isRewindable              setOptionFlags           
close                                        getOptionFlags                 nextDoc                        setOptions               
createMol                                getOptions                         notify                              setQueryMode             
equals                                     getQueryMode                   notifyAll                         setThreadCount           
estimateNumRecords          getRecordCount               read                             skipRecord               
getClass                                  getRecordCountMax        readDoc                      skipToNext               
getDocLabel                           hashCode                          readMol                       tell                     
getFile                                      importDoc                          readRecordAsText     toString                 
getFileName                           importMol                          seekForward               wait                     
getFormat                                isEndReached                 seekRecord               
getGlobalProperties              isGrabbingEnabled         seekRecordAtFraction     
getGrabbedMoleculeString  isMolMovie                         setFileName              
getLineCount                          isMultiSet                           setGrabbingEnabled     

This seems to be working. Then I keep trying,

>> inst.importMol = 'C1C(=O)CCC1';
??? No public field importMol exists for class chemaxon.formats.MolImporter.

and failed, but this one worked,

>> inst.importMol('C1C(=O)CCC1')
ans = Molecule@138b0d5[6a,6b]

as well as this one,

>> inst.importMol('C1C(=O)CCC1').getAtomCount()

ans =  6

But this one didn't,

>> importMol('C1C(=O)CCC1').getAtomCount()
??? Undefined variable "importMol" or class "importMol".

while these two did,

>> x = inst.importMol('C1C(=O)CCC1')
x = Molecule@10d08bc[6a,6b]
>> x.getAtomCount()

ans =  6

So, chemaxon classes are working from within MatLab.

Can you give me further instructions on the usage of MCES?

Looking forward,


ChemAxon 4a2fc68cd1

01-09-2011 14:18:54

Hi Omar,

Thank you for the several examples. I'm glad to hear that you managed to enable ChemAxon classes in MatLab.

Here is a short example how to use MCES in MatLab:

importer = chemaxon.formats.MolImporter
mol1 = importer.importMol('C1C(=O)CCC1')
mol2 = importer.importMol('CC(=O)C1CCCC1')

mces =
mces.setMolecules(mol1, mol2)

mces_atom_count = mces.getAtomCount()
mces_bond_count = mces.getBondCount()
mces_smiles = mces.getAsMolecule().toFormat('smiles')

This first three lines import two structures and store them in mol1 and mol2 variables. The second block performs MCES search, while the last three lines perform queries of the found MCES. I hope it will work, I could not try it currently as I don't have MatLab. You should get mces_smiles = 'C1CCCC1' as a result.


User 99e51048d1

01-09-2011 14:59:11

Hi Peter,

Thanks again. All the commands worked till the search. Below you can see the error message. Apparently, I don't have permission to exucute this command. I asked for an academic license but I haven't got any confirmation yet. I will contact the sale department, but if you have any comment I would appreciate it.


??? Java exception occurred:
chemaxon.license.LicenseException: No license file found.
Product name: MCES
License path:
Please contact to obtain the corresponding license.
Students and academic researchers are entitled of free use
through our Academic Package, for more information
please visit:

 at chemaxon.license.LicenseHandler.checkLicense(Unknown Source)





ChemAxon 4a2fc68cd1

01-09-2011 15:09:12

Hi Omar,

If you have contacted, you will get an acedemic license file soon. This file (license.cxl) should be copied to your user profile in chemaxon directory, i.e. c:\Users\<username>\chemaxon on Win7 or c:\Documents and Settings\<username>\chemaxon on Win XP.

Let me know if you received the license file and you tried the sample codes again.


User 99e51048d1

14-09-2011 17:43:42


I finally got the academic license and did as you told and everything run OK. I keep working and if get stuck come back to you.

Thanks a lot.


ChemAxon 4a2fc68cd1

15-09-2011 07:01:47

Hi Omar,

I'm glad to hear that.