MolConvert script/AppleScript for manipulating ~1000 files

User 7be2ac490f

08-06-2015 12:50:05

Hello, I am trying to convert files from .mol to .inchi using MolConvert. For one file I simply type: /Applications/ChemAxon/MarvinBeans/bin/molconvert inchi ~/myFile.mol > ~/myFile.inchi


I also make an image: /Applications/ChemAxon/MarvinBeans/bin/molconvert -o ~/myFile.png png ~/myFile.inchi 


Quality of image is not very good. Most probably I am doing something wrong.


But I have way to many files to do it all manually, so I wanted to automate the process, either using AppleScript or any other possible solution.


Here is my attempt (non-working so far, unfortunately) using AppleScript:


tell application "Finder"


    set folder to files of folder POSIX file "/Users/user/myFolderWithFiles/" as alias list


end tell


repeat with file in folder


if fileExtension is "mol" then


tell application "/Applications/ChemAxon/MarvinBeans/bin/molconvert" to inchi f > f.inchi


end tell


end if




end repeat


On this 'f' execution of the script fails: 'Expected end of line but found identifier.' Which is most probably due to my 0 AppleScript skill, which I actually have never used before.
What can I do in this case? How to write a script? 

ChemAxon 2cd598e7ad

10-06-2015 07:48:11

Hi,


According to AppleScript I can not provide a solution but I attach a small code that would do the job for you written in Java. Also I would like to mention that the generated pictures were not so good looking because they were "cleaned" in 3D. In the provided code I've inserted a "clean" call that transforms the molecule to it's 2D view. I suppose you would need it also while exporting into png.


Here is the code snippet:


public static void main(String[] args) throws IOException {
File folderOfMolFiles = new File("/absolute/path/to/mol/files/folder");
File folderToExportInchis = new File("/absolute/path/to/export/inchi/files");
for (String fileName : folderOfMolFiles.list()) {
if (fileName.endsWith("mol")) {
File molFile = new File(folderOfMolFiles, fileName);
MolImporter importer = new MolImporter(molFile);
Molecule mol = importer.read();
importer.close();
Cleaner.clean(mol, 2);
File inchiFile = new File(folderToExportInchis, fileName.replaceAll("mol$", "inchi"));
MolExporter exporter = new MolExporter(new FileOutputStream(inchiFile), "inchi");
exporter.write(mol);
exporter.close();
}
}


Regards, Domi

User 7be2ac490f

20-06-2015 08:23:37

Thanks a lot, now I see, how I should write such things)