Search in sources :

Example 1 with ReaderFactory

use of org.openscience.cdk.io.ReaderFactory in project ambit-mirror by ideaconsult.

the class CdkJmolAdapter method openBufferedReader.

/* **************************************************************
	 * the file related methods
	 * **************************************************************/
public Object openBufferedReader(String name, BufferedReader bufferedReader) {
    IChemFile chemFile = null;
    try {
        ISimpleChemObjectReader chemObjectReader = null;
        try {
            chemObjectReader = new ReaderFactory().createReader(bufferedReader);
        } catch (IOException ex) {
            return "Jmol: Error determining input format: " + ex;
        }
        if (chemObjectReader == null) {
            return "Jmol: unrecognized input format";
        }
        chemFile = (IChemFile) chemObjectReader.read(new org.openscience.cdk.ChemFile());
    } catch (CDKException ex) {
        return "Error reading input:" + ex;
    }
    if (chemFile == null)
        return "unknown error reading file";
    try {
        AtomTypeFactory factory = AtomTypeFactory.getInstance("pdb_atomtypes.txt", chemFile.getBuilder());
        // IAtomContainer atomContainer = (IAtomContainer)ChemFileManipulator.getAllInOneContainer(chemFile);
        Iterator<IChemSequence> seq = chemFile.chemSequences().iterator();
        while (seq.hasNext()) {
            Iterator<IChemModel> model = seq.next().chemModels().iterator();
            while (model.hasNext()) {
                Iterator<IAtomContainer> c = model.next().getMoleculeSet().atomContainers().iterator();
                while (c.hasNext()) {
                    Iterator<IAtom> it = c.next().atoms().iterator();
                    while (it.hasNext()) {
                        IAtom atom = it.next();
                        try {
                            factory.configure(atom);
                        } catch (CDKException exception) {
                            bcLogger.severe("Could not configure atom: " + atom);
                            bcLogger.log(Level.SEVERE, "  because: " + exception.getMessage(), exception);
                        }
                    }
                }
            }
        }
        return chemFile;
    } catch (Exception x) {
        return "Error configuring atoms input:" + x;
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) IChemFile(org.openscience.cdk.interfaces.IChemFile) ReaderFactory(org.openscience.cdk.io.ReaderFactory) IChemModel(org.openscience.cdk.interfaces.IChemModel) IOException(java.io.IOException) AtomTypeFactory(org.openscience.cdk.config.AtomTypeFactory) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException) ISimpleChemObjectReader(org.openscience.cdk.io.ISimpleChemObjectReader) IChemSequence(org.openscience.cdk.interfaces.IChemSequence) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 2 with ReaderFactory

use of org.openscience.cdk.io.ReaderFactory in project cdk by cdk.

the class ProteinPocketFinder method readBioPolymer.

/**
 * Creates from a PDB File a BioPolymer.
 */
private void readBioPolymer(String biopolymerFile) {
    // Read PDB file
    try (FileReader fileReader = new FileReader(biopolymerFile);
        ISimpleChemObjectReader reader = new ReaderFactory().createReader(fileReader)) {
        IChemFile chemFile = (IChemFile) reader.read((IChemObject) new ChemFile());
        // Get molecule from ChemFile
        IChemSequence chemSequence = chemFile.getChemSequence(0);
        IChemModel chemModel = chemSequence.getChemModel(0);
        IAtomContainerSet setOfMolecules = chemModel.getMoleculeSet();
        protein = (IBioPolymer) setOfMolecules.getAtomContainer(0);
    } catch (IOException | CDKException exc) {
        logger.error("Could not read BioPolymer from file>" + biopolymerFile + " due to: " + exc.getMessage());
        logger.debug(exc);
    }
}
Also used : IChemObject(org.openscience.cdk.interfaces.IChemObject) CDKException(org.openscience.cdk.exception.CDKException) IChemFile(org.openscience.cdk.interfaces.IChemFile) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) ReaderFactory(org.openscience.cdk.io.ReaderFactory) ChemFile(org.openscience.cdk.ChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) IChemModel(org.openscience.cdk.interfaces.IChemModel) ISimpleChemObjectReader(org.openscience.cdk.io.ISimpleChemObjectReader) FileReader(java.io.FileReader) IOException(java.io.IOException) IChemSequence(org.openscience.cdk.interfaces.IChemSequence)

Aggregations

IOException (java.io.IOException)2 CDKException (org.openscience.cdk.exception.CDKException)2 IChemFile (org.openscience.cdk.interfaces.IChemFile)2 IChemModel (org.openscience.cdk.interfaces.IChemModel)2 IChemSequence (org.openscience.cdk.interfaces.IChemSequence)2 ISimpleChemObjectReader (org.openscience.cdk.io.ISimpleChemObjectReader)2 ReaderFactory (org.openscience.cdk.io.ReaderFactory)2 FileReader (java.io.FileReader)1 ChemFile (org.openscience.cdk.ChemFile)1 AtomTypeFactory (org.openscience.cdk.config.AtomTypeFactory)1 IAtom (org.openscience.cdk.interfaces.IAtom)1 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)1 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)1 IChemObject (org.openscience.cdk.interfaces.IChemObject)1