ChemAxon Java Classes with Matlab...

User c1eed8df30

26-11-2013 00:17:13

Hello All!


I'm sorry if this is in the wrong section, I'm simply putting this in the same section that a similar question was placed in.


I'm having a lot of trouble using ChemAxon java classes in Matlab. Even after using the commands on the aforementioned similar question, I cannot seem to get the program to function correctly. They refer to an article via a dead link, but I've found it here.


I imported the jar files with the following command in MatLab


% Generate the list of jar files
jarDirectory = 'C:\Program Files (x86)\ChemAxon\JChem\lib';
dirResult = dir([jarDirectory, filesep, '*.jar']);
jars = cellfun( @(name)fullfile(jarDirectory, name), {dirResult.name}, 'UniformOutput', false );

% Add jars to the dynamic classpath
javaaddpath( jars );

% Check classpath
javaclasspath('-dynamic')


The "javaclasspath('-dynamic') command returns all of the .jar files that have been loaded by matlab, and I see all of ChemAxon's jar files. I should also note that I've also extracted all of the class files out of the jar files as well already, according to pkovac's instructions and tried everything on that page... to no avail :(


I'll simply paste what tardebut has inputted and return what my machine returns... in the hopes that someone knows what to do. ._.


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



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


>> inst = chemaxon.formats.MolImporter
No constructor 'chemaxon.formats.MolImporter' with matching signature found.


>> which importMol
importMol is a Java method  % chemaxon.formats.MolImporter method

>> methods('chemaxon.formats.MolImporter')
Methods for class chemaxon.formats.MolImporter:

MolImporter               
close                     
createMol                 
equals                    
estimateNumRecords        
getClass                  
getDocLabel               
getFile
[...]


>> inst.importMol = 'C1C(=O)CCC1';
(It does something... it creates a variable 'inst' that has the field 'importMol' filled with 'C1C(=O)CCC1'. This is a different result than what the other guy got. I think it has to do with "public classes" but I'm not sure what that means on Java :/)


>> inst.importMol('C1C(=O)CCC1')
Index exceeds matrix dimensions.


>> inst.importMol('C1C(=O)CCC1').getAtomCount()
Improper index matrix reference.


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



.... So yeah, any help would be greatly appreciated!

ChemAxon 5fc3e8d7d0

29-11-2013 13:16:39

Dear Yura,

I don't know why the old example doesn't work. Probably something has changed in process of Java method calling in MatLab.
But the following code works fine:


mol = chemaxon.formats.MolImporter.importMol('C1C(=O)CCC1');
mol.getAtomCount()

Best regards,
Laszlo