Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
URL url = new URL("http://www.chemaxon.com/marvin/mols-2d/mols.sdf");
MolImporter importer = new MolImporter(url.openStream(), "sdf");
importer.seekRecord(2, null);
Molecule molecule = importer.read();
 

For a complete source code, please see SeekingMolecule.java, seekRecord method.

...

Code Block
try {
	URL url = new URL(path);
    MolInputStream mis = new MolInputStream(url.openStream(), null, null, null);
    MRecordImporter importer = new MRecordImporter(mis, null);
    MDocument mDocument;
    while ((mDocument = importer.readDoc()) != null) {
        Molecule mol = (Molecule) mDocument.getMainMoleculeGraph();
        // do something with the molecule
    }
    importer.close();
} catch (MRecordParseException ex) {
    ex.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
 

For a complete source code, please see ImportMultiMoleculeFile.java, importMoleculeWithMRecordImporter method.

...

Code Block
MRecordReader recordReader = MFileFormatUtil.createRecordReader(
				new FileInputStream(new File("examples/io/basic/mols.rdf")),
				null, null, null);
MRecord record = null;
int recordCount = 0;
while ((record = recordReader.nextRecord()) != null) {
	// do something with the record	
	recordCount++;
}

 


For a complete source code, please see ImportRecords.java.