|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object chemaxon.marvin.util.MolExportModule
Abstract base class of molecule export modules.
An export module for format "XXX" must have the name
chemaxon.marvin.modules.XxxExport. Converted structures are returned by
molecule.toFormat
("xxx") or
toBinFormat
("xxx") method calls, as Strings or
byte[] arrays.
Example
The export module that can produce molecule files like the one in the
MolImportIface
example, is the following:
package chemaxon.marvin.modules; import chemaxon.struc.*; public class MyformatExport extends chemaxon.marvin.util.MolExportModule { public Objectconvert
(Molecule
mol) { StringBuffer s = stringBuffer; s.setLength(0); s.append(mol.getName
()); s.append('\n'); // atoms s.append(String.valueOf(mol.getAtomCount
())); s.append('\n'); for(int i = 0; i < mol.getAtomCount(); ++i) { MolAtom a = mol.getAtom(i); s.append(a.getSymbol
()); s.append('\t'); s.append(String.valueOf(a.getX
())); s.append('\t'); s.append(String.valueOf(a.getY
())); s.append('\n'); } // bonds s.append(String.valueOf(mol.getBondCount
())); s.append('\n'); for(int i = 0; i < mol.getBondCount(); ++i) { MolBond b = mol.getBond(i); s.append(String.valueOf(mol.indexOf
(b.getNode1()) + 1)); s.append('\t'); s.append(String.valueOf(mol.indexOf(b.getNode2()) + 1)); s.append('\t'); s.append(String.valueOf(b.getType
())); s.append('\n'); } return s.toString(); } }
After compiling and placing the class into Marvin's CLASSPATH, you can create "myformat" files with MolConverter,
and the applets:molconvert myformat pyrrole.mol -o pyrrole.myf
s = msketch.getMol("myformat");
Molecule.toFormat(java.lang.String)
,
Molecule.toBinFormat(java.lang.String)
Field Summary | |
protected java.lang.StringBuffer |
stringBuffer
This buffer can contain the molecule file contents, in case of a text format. |
Constructor Summary | |
MolExportModule()
|
Method Summary | |
protected void |
appendChars(int n,
char c)
Append a character n times to the string buffer. |
protected void |
appendLeft(java.lang.String t,
int n)
Append a string to the buffer in %-ns format. |
protected void |
appendRight(int t,
int n,
char c)
Append an integer to the buffer in the right hand side of an n-characters wide field. |
protected void |
appendRight(java.lang.String t,
int n,
char c)
Append a string to the buffer in the right hand side of an n-characters wide field. |
java.lang.Object |
close()
Close the stream. |
abstract java.lang.Object |
convert(Molecule mol)
Convert a molecule to a string or byte array. |
java.lang.String |
getFormat()
Returns the output format. |
protected java.lang.String |
getOptions()
Returns the output options. |
protected int |
getOptionSign()
Gets the sign of an option. |
static MolExportModule |
loadMarvinModule(java.lang.String fmt)
Loads a molecule export module for the specified format. |
java.lang.Object |
open(java.lang.String fmtopts)
Open the exporter stream. |
protected int |
parseOption(java.lang.String opts,
int i)
Parses the following option in the option string. |
protected Molecule |
preconvert(Molecule mol)
Optionally performs aromatization or addition of explicit Hydrogens atoms. |
protected Molecule |
preconvert(Molecule mol,
boolean xg)
Optionally performs aromatization or addition of explicit Hydrogens atoms. |
protected Molecule |
preconvert(Molecule mol,
boolean xg,
int xopts)
Optionally performs aromatization or addition of explicit Hydrogens atoms. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.StringBuffer stringBuffer
Constructor Detail |
public MolExportModule()
Method Detail |
public static MolExportModule loadMarvinModule(java.lang.String fmt) throws java.lang.SecurityException
fmt
- the format descriptor string
java.lang.SecurityException
- if the module cannot be loaded because of
a firewall problempublic java.lang.Object open(java.lang.String fmtopts) throws java.lang.IllegalArgumentException
fmtopts
- output file format and options
java.lang.IllegalArgumentException
- Invalid format string.getFormat()
,
getOptions()
public abstract java.lang.Object convert(Molecule mol) throws MolExportException
mol
- the molecule
MolExportException
- molecule cannot be exported in this formatpublic java.lang.Object close() throws MolExportException
MolExportException
- molecule cannot be exported in this formatpublic final java.lang.String getFormat()
protected final java.lang.String getOptions()
protected int parseOption(java.lang.String opts, int i) throws java.lang.IllegalArgumentException
opts
- the option stringi
- current index
java.lang.IllegalArgumentException
- in case of parsing errorprotected final int getOptionSign()
protected Molecule preconvert(Molecule mol)
mol
- the molecule
protected final Molecule preconvert(Molecule mol, boolean xg)
mol
- the moleculexg
- expand S-groups (true) or not (false)
protected final Molecule preconvert(Molecule mol, boolean xg, int xopts)
mol
- the moleculexg
- expand S-groups (true) or not (false)xopts
- expansion options
Expandable.expand(int)
,
Expandable.DEFAULT_OPTIONS
,
Expandable.MDL_EXPAND
protected final void appendChars(int n, char c)
stringBuffer
protected final void appendLeft(java.lang.String t, int n)
stringBuffer
protected final void appendRight(java.lang.String t, int n, char c)
stringBuffer
protected final void appendRight(int t, int n, char c)
stringBuffer
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |