|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectchemaxon.marvin.io.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
MolImportModule example, is the following:
package myio;
import chemaxon.struc.*;
public class MyFormatExport extends chemaxon.marvin.io.MolExportModule
{
public Object convert(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 int |
aromatize
Aromatize molecule according to basic aromatization if MoleculeGraph.AROM_BASIC + 1, according to general aromatization if MoleculeGraph.AROM_GENERAL + 1, dearomatize if -1, do nothing if 0. |
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 |
addData(Molecule mol,
MolAtom ma,
java.lang.String fieldName,
java.lang.String value)
Adds a data sgroup to the given atom in the given molecule with fieldName and value. |
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 |
getEncoding()
Gets the output encoding. |
java.lang.String |
getFormat()
Returns the output format. |
protected static java.lang.String |
getOptionDescriptors(java.util.ResourceBundle rc,
java.lang.String fmtname,
java.lang.String optnames,
java.util.List l)
Gets an array of option descriptors. |
OptionDescriptor[] |
getOptionDescriptors(java.lang.String fmtname)
Gets an array of option descriptors for the specified format. |
protected void |
getOptionDescriptors(java.lang.String fmtname,
java.lang.String optnames,
java.util.List l)
Gets an array of option descriptors. |
protected java.lang.String |
getOptions()
Returns the output options. |
protected int |
getOptionSign()
Gets the sign of the options. |
boolean |
isCleanable()
Tests whether 2D or 3D cleaning is meaningful for this output format. |
boolean |
isDocumentExport()
Tests if this export module is document export instead of a simple molecule export. |
static boolean |
isImplicitHcountImportant(MolAtom a)
Checks whether the number of implicit hydrogens is important information for an atom or not. |
boolean |
isImplicitHcountImportant(MoleculeGraph mol)
Checks whether the number of implicit hydrogens is important information for the atoms of mol or not. |
static boolean |
isSupportedEncoding(java.lang.String enc)
Test, whether the given charset name is supported by this JVM |
java.lang.Object |
open(java.lang.String fmtopts)
Opens the exporter stream. |
java.lang.Object |
open(java.lang.String fmtopts,
MPropertyContainer props)
Opens the exporter stream. |
protected int |
parseCharIfOptionSign(java.lang.String opts,
int i)
Parse the current character if it is an option sign. |
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,
boolean ih)
Optionally performs aromatization or addition of explicit Hydrogens atoms. |
protected MoleculeGraph |
preconvert(MoleculeGraph molg,
boolean xg,
int xopts,
boolean ih)
Optionally performs aromatization or addition of explicit Hydrogens atoms. |
java.lang.String |
setEncoding(java.lang.String opts,
java.lang.String enc)
Sets the output encoding using the export options. |
| 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
protected int aromatize
MoleculeGraph.AROM_BASIC,
MoleculeGraph.AROM_GENERAL| Constructor Detail |
public MolExportModule()
| Method Detail |
public final OptionDescriptor[] getOptionDescriptors(java.lang.String fmtname)
fmtname - the format name or null
protected void getOptionDescriptors(java.lang.String fmtname,
java.lang.String optnames,
java.util.List l)
fmtname - the format name or nulloptnames - option names or null for alll - the output list
public java.lang.Object open(java.lang.String fmtopts)
throws MolExportException
fmtopts - output file format and options
MolExportException - Invalid format string.getFormat(),
getOptions()
public java.lang.Object open(java.lang.String fmtopts,
MPropertyContainer props)
throws MolExportException
fmtopts - output file format and optionsprops - global GUI properties (currently allowed for MRV only in CmlExport)
MolExportException - Invalid format string.
public abstract java.lang.Object convert(Molecule mol)
throws MolExportException
mol - the molecule
MolExportException - molecule cannot be exported in this format
public 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()
public boolean isDocumentExport()
false in the default implementationpublic boolean isCleanable()
public static boolean isImplicitHcountImportant(MolAtom a)
a - the atom
public boolean isImplicitHcountImportant(MoleculeGraph mol)
mol - the molecule
isImplicitHcountImportant(chemaxon.struc.MolAtom)
public java.lang.String setEncoding(java.lang.String opts,
java.lang.String enc)
opts - the export optionsenc - the default encoding
java.nio.charset.IllegalCharsetNameException - if the encoding is illegal
java.nio.charset.UnsupportedCharsetException - if the encoding is unsupportedpublic java.lang.String getEncoding()
public static boolean isSupportedEncoding(java.lang.String enc)
enc - the name of the charset
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 int parseCharIfOptionSign(java.lang.String opts,
int i)
opts - the option stringi - current character index
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,
boolean ih)
mol - the moleculexg - expand S-groups (true) or not (false)xopts - expansion optionsih - if true, important implicit H-s are converted to attached
data.
Expandable.expand(int),
Expandable.DEFAULT_OPTIONS,
Expandable.MDL_EXPAND
protected final MoleculeGraph preconvert(MoleculeGraph molg,
boolean xg,
int xopts,
boolean ih)
molg - the moleculexg - expand S-groups (true) or not (false)xopts - expansion optionsih - if true, important implicit H-s are converted to attached
data.
Expandable.expand(int),
Expandable.DEFAULT_OPTIONS,
Expandable.MDL_EXPAND
protected void addData(Molecule mol,
MolAtom ma,
java.lang.String fieldName,
java.lang.String value)
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
protected static java.lang.String getOptionDescriptors(java.util.ResourceBundle rc,
java.lang.String fmtname,
java.lang.String optnames,
java.util.List l)
rc - the resource bundle containing the option infofmtname - the format name or nulloptnames - space separated list of option namesl - the output list
null
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||