Package chemaxon.marvin.io
Class MolExportModule
java.lang.Object
chemaxon.marvin.io.MolExportModule
- Direct Known Subclasses:
MolExport
Abstract base class of molecule export modules.
An export module for format "XXX" must have the name
chemaxon.marvin.modules.XxxExport.
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");
- Since:
- Marvin 2.7.9
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
Add numbers to atoms corresponding to the (IUPAC) naming of the molecule.protected int
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
Add Hydrogen atoms if 1, remove if -1, do nothing if 0.protected StringBuffer
This buffer can contain the molecule file contents, in case of a text format. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Adds a data sgroup to the given atom in the given molecule with fieldName and value.protected final void
appendChars
(int n, char c) Append a character n times to the string buffer.protected final void
appendLeft
(String t, int n) Append a string to the buffer in %-ns format.protected final 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 final 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.close()
Close the stream.abstract Object
Convert a molecule to a string or byte array.Gets the output encoding.final String
Returns the output format.final 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 static String
getOptionDescriptors
(ResourceBundle rc, String fmtname, String optnames, List<OptionDescriptor> l) Gets an array of option descriptors.protected final String
Returns the output options.protected final int
Gets the sign of the options.boolean
Tests whether 2D or 3D cleaning is meaningful for this output format.boolean
Tests if this export module is document export instead of a simple molecule export.static boolean
Checks whether the number of implicit hydrogens is important information for an atom or not.boolean
Checks whether the number of implicit hydrogens is important information for the atoms of mol or not.protected static int
Tests whether the option string contains the specified substring at the specified position.Opens the exporter stream.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 final MoleculeGraph
preconvert
(MoleculeGraph molg, boolean xg, int xopts, boolean ih) Deprecated, for removal: This API element is subject to removal in a future version.protected final Molecule
preconvert
(Molecule mol, boolean xg) Optionally performs aromatization or addition of explicit Hydrogens atoms.protected final Molecule
preconvert
(Molecule mol, boolean xg, int xopts, boolean ih) Optionally performs aromatization or addition of explicit Hydrogens atoms.setEncoding
(String opts, String enc) Sets the output encoding using the export options.void
Pass and set the global GUI properties container.
-
Field Details
-
stringBuffer
This buffer can contain the molecule file contents, in case of a text format. -
aromatize
protected int aromatizeAromatize 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. -
hydrogenize
protected int hydrogenizeAdd Hydrogen atoms if 1, remove if -1, do nothing if 0. -
addNumbering
protected boolean addNumberingAdd numbers to atoms corresponding to the (IUPAC) naming of the molecule.
-
-
Constructor Details
-
MolExportModule
public MolExportModule()
-
-
Method Details
-
getOptionDescriptors
Gets an array of option descriptors for the specified format.- Parameters:
fmtname
- the format name ornull
- Since:
- Marvin 5.0, 06/06/2007
-
getOptionDescriptors
Gets an array of option descriptors.- Parameters:
fmtname
- the format name ornull
optnames
- option names ornull
for alll
- the output list- Since:
- Marvin 5.0, 06/06/2007
-
open
Opens the exporter stream. Overriding methods should call super.open(fmtopts) at the beginning. In case of some many-molecule formats such as RDfile, the files begin with a header. This header must be returned by open(), either as a String object or a byte[] array.- Parameters:
fmtopts
- output file format and options- Returns:
- null (file header or null in overriding methods)
- Throws:
MolExportException
- Invalid format string.- See Also:
-
open
Opens the exporter stream. Overriding methods should call super.open(fmtopts, props) at the beginning. In case of some many-molecule formats such as RDfile, the files begin with a header. This header must be returned by open(), either as a String object or a byte[] array.- Parameters:
fmtopts
- output file format and optionsprops
- global GUI properties (currently allowed for MRV in CmlExport and CXON)- Returns:
- null (file header or null in overriding methods)
- Throws:
MolExportException
- Invalid format string.- Since:
- Marvin 4.1, 03/22/2006
-
convert
Convert a molecule to a string or byte array.When converted to a String, it should end with a '\n' character.
- Parameters:
mol
- the molecule- Returns:
- a string or a byte array, null for failure
- Throws:
MolExportException
- molecule cannot be exported in this format
-
close
Close the stream. This method is called after the last convert().- Returns:
- last section of the file as a string or a byte array, or null
- Throws:
MolExportException
- molecule cannot be exported in this format
-
getFormat
Returns the output format. -
getOptions
Returns the output options. -
isDocumentExport
public boolean isDocumentExport()Tests if this export module is document export instead of a simple molecule export.- Returns:
false
in the default implementation- Since:
- Marvin 4.0, 07/01/2005
-
isCleanable
public boolean isCleanable()Tests whether 2D or 3D cleaning is meaningful for this output format.- Returns:
- true in the default implementation
- Since:
- Marvin 4.1, 02/12/2006
-
isImplicitHcountImportant
Checks whether the number of implicit hydrogens is important information for an atom or not. Implicit H count is exported: - if the atom has aromatic bond, has exactly one implicit hydrogen and can be ambiguous according to local aromatic valence check. Possible atoms are: B, C-, C+, N, P, As, S+, O+ - if the atom is an S atom and has 3 bonds and an implicit H.- Parameters:
atom
- the atom- Returns:
- true if implicit H count is important on the atom.
- Since:
- Marvin 3.5, 10/08/2004
-
isImplicitHcountImportant
Checks whether the number of implicit hydrogens is important information for the atoms of mol or not.- Parameters:
mol
- the molecule- Returns:
- true if there is important implicit H in the molecule.
- Since:
- Marvin 4.0.2, 08/24/2005
- See Also:
-
setEncoding
Sets the output encoding using the export options.- Parameters:
opts
- the export optionsenc
- the default encoding- Returns:
- the value of the encoding field or null
- Throws:
IllegalCharsetNameException
- if the encoding is illegalUnsupportedCharsetException
- if the encoding is unsupported- Since:
- Marvin 4.0.4, 01/03/2006
-
getEncoding
Gets the output encoding.- Returns:
- the value of the encoding field or null
-
parseOption
Parses the following option in the option string.- Parameters:
opts
- the option stringi
- current index- Returns:
- index of the next option, or i if the current option is unknown
- Throws:
IllegalArgumentException
- in case of parsing error
-
nextOpt
Tests whether the option string contains the specified substring at the specified position.- Parameters:
opts
- the option stringi
- current indexs
- the substring- Returns:
i
+ length ofs
ifopts
containss
at positioni
, i otherwise- Since:
- Marvin 5.1.4, 11/09/2008
-
getOptionSign
protected final int getOptionSign()Gets the sign of the options. The sign is a + or - character preceding the option(s) in the string.- Returns:
- 1, 0 or -1
-
parseCharIfOptionSign
Parse the current character if it is an option sign.- Parameters:
opts
- the option stringi
- current character index- Returns:
- i + 1 if character at i is an option sign, i otherwise
- Since:
- Marvin 4.1.9, 06/06/2007
-
preconvert
Optionally performs aromatization or addition of explicit Hydrogens atoms. Contracted S-groups are also expanded.- Parameters:
mol
- the molecule- Returns:
- the converted molecule or the argument (if conversion is not perfomed)
-
preconvert
Optionally performs aromatization or addition of explicit Hydrogens atoms. Contracted S-groups can also be expanded.- Parameters:
mol
- the moleculexg
- expand S-groups (true) or not (false)- Returns:
- the converted molecule or the argument (if conversion is not perfomed)
-
preconvert
Optionally performs aromatization or addition of explicit Hydrogens atoms. Contracted S-groups can also be expanded.- Parameters:
mol
- the moleculexg
- expand S-groups (true) or not (false)xopts
- expansion optionsReih
- if true, important implicit H-s are converted to attached data.- Returns:
- the converted molecule or the argument (if conversion is not perfomed)
- See Also:
-
preconvert
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) protected final MoleculeGraph preconvert(MoleculeGraph molg, boolean xg, int xopts, boolean ih) Deprecated, for removal: This API element is subject to removal in a future version.Marvin 6.2 usepreconvert(chemaxon.struc.Molecule, boolean, int, boolean)
insteadOptionally performs aromatization or addition of explicit Hydrogens atoms. Contracted S-groups can also be expanded.- Parameters:
molg
- the moleculexg
- expand S-groups (true) or not (false)xopts
- expansion optionsih
- if true, important implicit H-s are converted to attached data.- Returns:
- the converted molecule or the argument (if conversion is not perfomed)
- Since:
- Marvin 3.5.1, 11/16/2004
- See Also:
-
addData
Adds a data sgroup to the given atom in the given molecule with fieldName and value.- Since:
- Marvin 4.0.1 8/19/2005
-
appendChars
protected final void appendChars(int n, char c) Append a character n times to the string buffer.- See Also:
-
appendLeft
Append a string to the buffer in %-ns format.- See Also:
-
appendRight
Append a string to the buffer in the right hand side of an n-characters wide field. The left side is filled with the specified characters.- See Also:
-
appendRight
protected final 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. The left side is filled with the specified characters.- See Also:
-
getOptionDescriptors
protected static String getOptionDescriptors(ResourceBundle rc, String fmtname, String optnames, List<OptionDescriptor> l) Gets an array of option descriptors.- Parameters:
rc
- the resource bundle containing the option infofmtname
- the format name ornull
optnames
- space separated list of option namesl
- the output list- Returns:
- the nonprocessed option names or
null
- Since:
- Marvin 5.0, 06/06/2007
-
setGlobalGUIProperties
Pass and set the global GUI properties container.- Since:
- Marvin 6.0, 2013.03.26.
-
preconvert(chemaxon.struc.Molecule, boolean, int, boolean)
instead