Examples of IChemFile


Examples of org.openscience.cdk.interfaces.IChemFile

   * @return The CDK molecule.
   * @throws Exception
   */
  public static IMolecule cmlToMolecule(Element cmlMol) throws Exception {
    ByteArrayInputStream bais = new ByteArrayInputStream(cmlMol.toXML().getBytes());
    IChemFile cf = (IChemFile) new CMLReader(bais).read(new ChemFile());
    IMolecule mol = cf.getChemSequence(0).getChemModel(0).getMoleculeSet().getMolecule(0);
    configureMolecule(mol);
    return mol;
  }
View Full Code Here

Examples of org.openscience.cdk.interfaces.IChemFile

    configureMolecule(mol);
    return mol;
  }
 
  static IMolecule cmlToMolecule(InputStream is) throws Exception {
    IChemFile cf = (IChemFile) new CMLReader(is).read(new ChemFile());
    IMolecule mol = cf.getChemSequence(0).getChemModel(0).getMoleculeSet().getMolecule(0);
    configureMolecule(mol);
    return mol;   
  }
View Full Code Here

Examples of org.openscience.cdk.interfaces.IChemFile

    public static IChemModel getChemModelFromReader(ISimpleChemObjectReader cor,AbstractJChemPaintPanel panel)
            throws CDKException {
      panel.get2DHub().setRGroupHandler(null);
      String error = null;
        ChemModel chemModel = null;
        IChemFile chemFile = null;
        if (cor.accepts(IChemFile.class) && chemModel==null) {
            // try to read a ChemFile
            try {
                chemFile = (IChemFile) cor.read((IChemObject) new ChemFile());
                if (chemFile == null) {
                    error = "The object chemFile was empty unexpectedly!";
                }
            } catch (Exception exception) {
                error = "Error while reading file: " + exception.getMessage();
                exception.printStackTrace();
            }
        }
        if (error != null) {
            throw new CDKException(error);
        }
        if (chemModel == null && chemFile != null) {
            chemModel = (ChemModel) chemFile.getChemSequence(0).getChemModel(0);
        }
        if (cor.accepts(ChemModel.class) && chemModel==null) {
            // try to read a ChemModel
            try {

                chemModel = (ChemModel) cor.read((IChemObject) new ChemModel());
                if (chemModel == null) {
                    error = "The object chemModel was empty unexpectedly!";
                }
            } catch (Exception exception) {
                error = "Error while reading file: " + exception.getMessage();
                exception.printStackTrace();
            }
        }

        // Smiles reading
        if (cor.accepts(IAtomContainerSet.class) && chemModel==null) {
            // try to read a Molecule set
            try {
                IAtomContainerSet som = (AtomContainerSet) cor.read(new AtomContainerSet());
                chemModel = new ChemModel();
                chemModel.setMoleculeSet(som);
                if (chemModel == null) {
                    error = "The object chemModel was empty unexpectedly!";
                }
            } catch (Exception exception) {
                error = "Error while reading file: " + exception.getMessage();
                exception.printStackTrace();
            }
        }

        // MDLV3000 reading
        if (cor.accepts(IAtomContainer.class) && chemModel==null) {
            // try to read a Molecule
                IAtomContainer mol = (AtomContainer) cor.read(new AtomContainer());
                if(mol!=null )
                    try{
                        IAtomContainerSet newSet = new AtomContainerSet();
                        newSet.addAtomContainer(mol);
                        chemModel = new ChemModel();
                        chemModel.setMoleculeSet(newSet);
                        if (chemModel == null) {
                            error = "The object chemModel was empty unexpectedly!";
                        }
                    } catch (Exception exception) {
                        error = "Error while reading file: " + exception.getMessage();
                        exception.printStackTrace();
                    }
        }

        // RGroupQuery reading
        if (cor.accepts(RGroupQuery.class) && chemModel==null) {
          IRGroupQuery rgroupQuery = (RGroupQuery) cor.read(new RGroupQuery(DefaultChemObjectBuilder.getInstance()));
          if(rgroupQuery!=null )
            try{
              chemModel = new ChemModel();
              RGroupHandler rgHandler =  new RGroupHandler(rgroupQuery, panel);
              panel.get2DHub().setRGroupHandler(rgHandler);
              chemModel.setMoleculeSet(rgHandler.getMoleculeSet(chemModel));
              rgHandler.layoutRgroup();
             
            } catch (Exception exception) {
              error = "Error while reading file: " + exception.getMessage();
              exception.printStackTrace();
            }
        }
       
        if (error != null) {
            throw new CDKException(error);
        }

        if (chemModel == null && chemFile != null) {
            chemModel = (ChemModel) chemFile.getChemSequence(0).getChemModel(0);
        }

      //SmilesParser sets valencies, switch off by default.
        if(cor instanceof SMILESReader){
          IAtomContainer allinone = JChemPaintPanel.getAllAtomContainersInOne(chemModel);
View Full Code Here

Examples of org.openscience.cdk.interfaces.IChemFile

                try {
                    if (reader.accepts(IAtomContainer.class)) {
                        toPaste = (IAtomContainer) reader.read(readMolecule);
                    } else if (reader.accepts(ChemFile.class)) {
                        toPaste = readMolecule;
                        IChemFile file = (IChemFile) reader.read(new ChemFile());
                        for (IAtomContainer ac :
                            ChemFileManipulator.getAllAtomContainers(file)) {
                            toPaste.add(ac);

                        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.