extending MolImport

User c8c126404b

27-05-2009 08:35:48

Hi,


In the past (Marvin 3.x) I have extended the MolImport class to the some pre-processing. The code I had was something like this:


package chemaxon.marvin.modules;

import chemaxon.formats.MolInputStream;

import chemaxon.struc.Molecule;

public class XXXMolImport extends MolImport {

public void initMolImport(MolInputStream mis, String opts) throws IOException {
mis.getFilePointer();
String x = mis.readLine();
// some code here
MolInputStream cmis = new MolInputStream(s);
super.initMolImport(cmis, opts);
}

public boolean readMol(Molecule mol) throws IOException {
return super.readMol(mol);
}

public boolean skipToNext() {
return false;
}
}


 


now I want to modify this code to run under marvin 5.x. Things have changed... Is the follwing correct:


package chemaxon.marvin.modules;

import chemaxon.formats.MolInputStream;

import chemaxon.marvin.io.formats.mdl.MolImport;

public class XXXMolImport extends MolImport {

public void initMolImport(MolInputStream mis) throws IOException {
mis.getFilePointer();
String x = mis.readLine();
// some code here
super.initMolImport(cmis);
}
}


Where should I place my class file? in chemaxon.marvin.modules or in chemaxon.marvin.io.formats.mdl? How to make my new format "xxxMol" visible? Any issues with the digital signatures? In the past I had to unzip all your jars and sign them with my signature.


Any help will be much appreciated.


Regards,


Plamen

User ef5e605ae6

27-05-2009 19:33:41

Hi,


There is a nice example about custom file format creation in the examples/myformat directory of Marvin but I do not know whether it is also present in the released version of marvinbeans or applets. I'm afraid it is not present, but I pass this topic to someone else who might know it.


Peter

User c8c126404b

28-05-2009 07:03:56

Hi Peter!
I can't find the example code.


What is important in my case is that I don't want to build a new format from scratch, but extend the existing Mol format.


Would be great if someone sends the myformat example.


Regards,


Plamen

ChemAxon 909aee4527

28-05-2009 12:35:03

Hi Plamen,


the example is attached, we will include it in our future releases.


Kind regards,
Judit

User ef5e605ae6

28-05-2009 14:10:40











Hi Plamen,


I realized that the method demonstrated in the example works only if you use it in your own program, because registerFormat is called in the main method. If you want to use your xxxmol format in a chemaxon applet like JMSketch, then currently the only way is to make your own applet class by extending JMSketch and calling registerFormat from the static block:


public class MySketchApplet extends JMSketch {
public static final MFileFormat XXXMOL = new MFileFormat(...);
static {
MFileFormatUtil.registerFormat(XXXMOL);
}
}


I found a better solution now which will be available in Marvin 5.2.3. You can define the public static final MFileFormat XXXMOL anywhere you want, e.g. in a class called yourpackage.YourInit, but to use it in Marvin, you will have to extract jmarvin.jar (for the applets) or MarvinBeans.jar, edit chemaxon/formats/registry-user.properties and insert the following line:xxxmol=yourpackage.YourInit.XXXMOL


Peter


User c8c126404b

28-05-2009 14:22:15

Hi Peter.


Thanks for your help! Maybe I shoud wait until the next release. (this custom MOL format is not urgent for me). In the old 3.x Marvin I didn't have to register anything - just drop the class file in the right directory. A lot has changed since then... I am just trying to catch up.


Regards,


Plamen

User ef5e605ae6

28-05-2009 15:19:50











The difference is that
- format recognition did not work for user defined formats,
- user defined formats did not appear in menus and list boxes (in open/save dialogs and edit source window)
Starting from Marvin 5.0, menu generation is automatic and file format recognition is fully object oriented, you can create your own recognizer for xxxmol if you want. Since menus are generated using the meta info stored in the MFileFormat objects, your format will also be choosable in the GUI.


regards,
Peter