public abstract class MolExportModule extends Object
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 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.getAtom1()) + 1)); s.append('\t'); s.append(String.valueOf(mol.indexOf(b.getAtom2()) + 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)
Modifier and Type | Field and Description |
---|---|
protected boolean |
addNumbering
Add numbers to atoms corresponding to the (IUPAC) naming of the molecule.
|
protected int |
aromatize
Aromatize molecule according to basic aromatization
if MoleculeGraph.AROM_BASIC + 1,
according to general aromatization if MoleculeGraph.AROM_GENERAL + 1,
etc, dearomatize if -1, do nothing if 0.
|
protected int |
hydrogenize
Add Hydrogen atoms if 1, remove if -1, do nothing if 0.
|
protected StringBuffer |
stringBuffer
This buffer can contain the molecule file contents, in case of a
text format.
|
Constructor and Description |
---|
MolExportModule() |
Modifier and Type | Method and Description |
---|---|
protected void |
addData(Molecule mol,
MolAtom ma,
String fieldName,
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(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(String t,
int n,
char c)
Append a string to the buffer in the right hand side of an n-characters
wide field.
|
Object |
close()
Close the stream.
|
abstract Object |
convert(Molecule mol)
Convert a molecule to a string or byte array.
|
String |
getEncoding()
Gets the output encoding.
|
String |
getFormat()
Returns the output format.
|
protected static String |
getOptionDescriptors(ResourceBundle rc,
String fmtname,
String optnames,
List<OptionDescriptor> l)
Gets an array of option descriptors.
|
OptionDescriptor[] |
getOptionDescriptors(String fmtname)
Gets an array of option descriptors for the specified format.
|
protected void |
getOptionDescriptors(String fmtname,
String optnames,
List<OptionDescriptor> l)
Gets an array of option descriptors.
|
protected 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 atom)
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.
|
protected static int |
nextOpt(String opts,
int i,
String s)
Tests whether the option string contains the specified substring at
the specified position.
|
Object |
open(String fmtopts)
Opens the exporter stream.
|
Object |
open(String fmtopts,
MPropertyContainer props)
Opens the exporter stream.
|
protected int |
parseCharIfOptionSign(String opts,
int i)
Parse the current character if it is an option sign.
|
protected int |
parseOption(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)
Deprecated.
Marvin 6.2 use
preconvert(chemaxon.struc.Molecule, boolean, int, boolean) instead |
String |
setEncoding(String opts,
String enc)
Sets the output encoding using the export options.
|
void |
setGlobalGUIProperties(MPropertyContainer ggp)
Pass and set the global GUI properties container.
|
protected StringBuffer stringBuffer
protected int aromatize
protected int hydrogenize
protected boolean addNumbering
public final OptionDescriptor[] getOptionDescriptors(String fmtname)
fmtname
- the format name or null
protected void getOptionDescriptors(String fmtname, String optnames, List<OptionDescriptor> l)
fmtname
- the format name or null
optnames
- option names or null
for alll
- the output listpublic Object open(String fmtopts) throws MolExportException
fmtopts
- output file format and optionsMolExportException
- Invalid format string.getFormat()
,
getOptions()
public Object open(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 Object convert(Molecule mol) throws MolExportException
mol
- the moleculeMolExportException
- molecule cannot be exported in this formatpublic Object close() throws MolExportException
MolExportException
- molecule cannot be exported in this formatpublic final String getFormat()
protected final String getOptions()
public boolean isDocumentExport()
false
in the default implementationpublic boolean isCleanable()
public static boolean isImplicitHcountImportant(MolAtom atom)
atom
- the atompublic boolean isImplicitHcountImportant(MoleculeGraph mol)
mol
- the moleculeisImplicitHcountImportant(chemaxon.struc.MolAtom)
public String setEncoding(String opts, String enc)
opts
- the export optionsenc
- the default encodingIllegalCharsetNameException
- if the encoding is illegalUnsupportedCharsetException
- if the encoding is unsupportedpublic String getEncoding()
protected int parseOption(String opts, int i) throws IllegalArgumentException
opts
- the option stringi
- current indexIllegalArgumentException
- in case of parsing errorprotected static int nextOpt(String opts, int i, String s)
opts
- the option stringi
- current indexs
- the substringi
+ length of s
if opts
contains s
at position i
, i otherwiseprotected final int getOptionSign()
protected int parseCharIfOptionSign(String opts, int i)
opts
- the option stringi
- current character indexprotected Molecule preconvert(Molecule mol)
mol
- the moleculeprotected 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 optionsReih
- if true, important implicit H-s are converted to attached
data.Expandable.expand(int)
,
Expandable.DEFAULT_OPTIONS
,
Expandable.MDL_EXPAND
@Deprecated protected final MoleculeGraph preconvert(MoleculeGraph molg, boolean xg, int xopts, boolean ih)
preconvert(chemaxon.struc.Molecule, boolean, int, boolean)
insteadmolg
- 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, String fieldName, String value)
protected final void appendChars(int n, char c)
stringBuffer
protected final void appendLeft(String t, int n)
stringBuffer
protected final void appendRight(String t, int n, char c)
stringBuffer
protected final void appendRight(int t, int n, char c)
stringBuffer
protected static String getOptionDescriptors(ResourceBundle rc, String fmtname, String optnames, List<OptionDescriptor> l)
rc
- the resource bundle containing the option infofmtname
- the format name or null
optnames
- space separated list of option namesl
- the output listnull
public void setGlobalGUIProperties(MPropertyContainer ggp)
ggp
-