|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectchemaxon.marvin.io.MolImportModule
public abstract class MolImportModule
Base class of Molecule import modules.
Example
I want to read a molecule from a file in a special format ("myformat")
that stores the molecule name, the atom symbols, the x, y coordinates and
the bond orders:
To read this file ("pyrrole.myf"), I create an import module for "myformat":Pyrrole 5 N -0.09625 2.75245 C -1.42989 3.52245 C -1.42989 5.06245 C 1.23739 5.06245 C 1.23739 3.52245 5 1 2 1 2 3 2 3 4 1 4 5 2 5 1 1
package myio;
import chemaxon.struc.*;
import chemaxon.formats.MolInputStream;
import chemaxon.formats.MolFormatException;
import java.util.StringTokenizer;
public class MyFormatImport extends chemaxon.marvin.io.MolImportModule
{
private MolInputStream istream;
public void initMolImport(MolInputStream mis) {
istream = mis;
}
public boolean readMol(Molecule mol) throws MolFormatException {
// initialize molecule object
mol.clearForImport("myformat");
mol.setStartPosition(istream.getFilePointer());
// read the molecule
String line = istream.readLine();
if(line == null) // end of file
return false;
mol.setName(line.trim()); // set molecule name
mol.setDim(2); // set number of dimensions
try {
line = istream.readLine();
int numAtoms = Integer.parseInt(line.trim());
for(int i = 0; i < numAtoms; ++i) {
line = istream.readLine();
StringTokenizer st = new StringTokenizer(line);
int atno = MolAtom.numOf(st.nextToken());
double x = Double.valueOf(st.nextToken()).doubleValue();
double y = Double.valueOf(st.nextToken()).doubleValue();
MolAtom a = mol.reuseAtom(atno, i);
a.setXY(x, y);
}
mol.endReuse(numAtoms);
line = istream.readLine();
int numBonds = Integer.parseInt(line.trim());
for(int i = 0; i < numBonds; ++i) {
line = istream.readLine();
StringTokenizer st = new StringTokenizer(line);
int atomIndex1 = Integer.parseInt(st.nextToken()) - 1;
int atomIndex2 = Integer.parseInt(st.nextToken()) - 1;
int order = Integer.parseInt(st.nextToken());
MolBond b = new MolBond(mol.getAtom(atomIndex1),
mol.getAtom(atomIndex2), order);
mol.add(b);
mol.valenceCheck(null); // to set the implicit hydrogens
}
} catch(NumberFormatException ex) {
throw new MolFormatException("error in molecule file");
}
// memorize the last file position corresponding to this molecule
mol.setEndPosition(istream.getFilePointer());
return true;
}
public boolean createMol() {
return new Molecule();
}
}
After compiling and placing the class into Marvin's CLASSPATH, I can read pyrrole.myf with Marvin applications,
and the applets:molconvert smiles "pyrrole.myf(myformat:)" msketch "pyrrole.myf(myformat:)" mview "pyrrole.myf(myformat:)"
<param NAME="mol" VALUE="pyrrole.myf(myformat:)">
msketch.setMol("pyrrole.myf(myformat:)");
| Nested Class Summary | |
|---|---|
static class |
MolImportModule.PreferredView
|
| Constructor Summary | |
|---|---|
MolImportModule()
|
|
| Method Summary | |
|---|---|
abstract Molecule |
createMol()
Creates a new target molecule object for the import. |
int |
getLineCount()
Returns the line count in the molecule input stream. |
MolImportModule.PreferredView |
getPreferredView()
Specifies which view style is preferred (for instance in MarvinView) for this format. |
void |
initMolImport(MolInputStream is)
Initializes the import module. |
void |
initMolImport(MRecord record,
java.lang.String fname)
Initializes the import module. |
boolean |
isDocumentImporter()
Tests whether this module is a document importer or not. |
MDocument |
readDocument(MDocument doc)
Reads the next document. |
abstract boolean |
readMol(Molecule m)
Reads the next molecule. |
void |
setOptions(java.lang.String options)
Sets the import options. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MolImportModule()
| Method Detail |
|---|
public void setOptions(java.lang.String options)
throws java.lang.IllegalArgumentException
options - import options
java.lang.IllegalArgumentException - if the specified options cannot be
interpreted by the import module
public void initMolImport(MRecord record,
java.lang.String fname)
throws MolFormatException,
java.io.IOException
initMolImport(chemaxon.formats.MolInputStream)
with the input stream generated from the molecule string
stored in the specified molecule record.
Subclasses should override either this method
(if the import uses data fields in MRecord)
or else initMolImport(chemaxon.formats.MolInputStream).
record - the molecule recordfname - the input filename or URL
MolFormatException - if the file cannot be read because of
a molecule file format related error
java.io.IOException - an I/O error occured while reading the file
public void initMolImport(MolInputStream is)
throws MolFormatException,
java.io.IOException
initMolImport(MRecord, String) )}
if the import uses other fields in MRecord.
is - the molecule input stream
MolFormatException - if the file cannot be read because of
a molecule file format related error
java.io.IOException - an I/O error occured while reading the file
public abstract boolean readMol(Molecule m)
throws MolFormatException,
java.io.IOException
true if reading was successful,
false if there is nothing to read (EOF reached)
MolFormatException - if the file cannot be read because of
a molecule file format related error
java.io.IOException - an I/O error occured while reading the filepublic abstract Molecule createMol()
public boolean isDocumentImporter()
true if it it is a document readers,
false if it is a simple molecule readerreadDocument(MDocument)
public MDocument readDocument(MDocument doc)
throws java.io.IOException
isDocumentImporter() returns true.
doc - target document or null
java.io.IOException - the file is in bad format or could not readisDocumentImporter()public int getLineCount()
public MolImportModule.PreferredView getPreferredView()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||