Package org.openscience.cdk

Examples of org.openscience.cdk.ChemModel


public class Structure2DComponent extends JChemPaintViewerPanel {

  public Structure2DComponent(String structure) throws CDKException {

    super(new ChemModel(), 0, 0, true, false, null);

    // Load the structure
    StringReader reader = new StringReader(structure);

    MDLReader molReader = new MDLReader(reader);
    ChemModel chemModel = new ChemModel();
    chemModel = (ChemModel) molReader.read(chemModel);

    setChemModel(chemModel);

  }
View Full Code Here


     */
    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();
View Full Code Here

                        }
                  } else if (reader.accepts(RGroupQuery.class)) {
                rgrpQuery=true;
                    IRGroupQuery rgroupQuery = (RGroupQuery) reader.read(new RGroupQuery(DefaultChemObjectBuilder.getInstance()));
                chemModel = new ChemModel();
                RGroupHandler rgHandler =  new RGroupHandler(rgroupQuery, this.jcpPanel);
                this.jcpPanel.get2DHub().setRGroupHandler(rgHandler);
                chemModel.setMoleculeSet(rgHandler.getMoleculeSet(chemModel));
                rgHandler.layoutRgroup();
               
View Full Code Here

     * @param url location
     * @return InChI instance
     * @throws CDKException InChI could not be generated
     */
    public static IChemModel readInChI(URL url) throws CDKException {
        IChemModel chemModel = new ChemModel();
        try {
            IAtomContainerSet moleculeSet = new AtomContainerSet();
            chemModel.setMoleculeSet(moleculeSet);

            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = in.readLine()) != null) {
                if (line.toLowerCase().startsWith("inchi=")) {
View Full Code Here

    if (scrollbarParam != null && scrollbarParam.equals("false")) {
      fitToScreen = true;
    }
    JChemPaintViewerPanel p
        = new JChemPaintViewerPanel(
                new ChemModel(), getWidth(), getHeight(), fitToScreen, debug, this)
    setTheJcpp(p);
    this.add(p);
    super.init();
  }
View Full Code Here

   
            } catch (Exception exception) {
                theJcpp.announceError(exception);
            }
        } else {
            theJcpp.setChemModel(new ChemModel());
        }
    }
View Full Code Here

        if (dialog == null) {
            dialog = new TextViewDialog(frame, "InChI", null, false, 40, 2);
        }

        ChemModel model = (ChemModel) jcpPanel.getChemModel();
        if (model.getReactionSet() != null
                && model.getReactionSet().getReactionCount() > 0) {
            dialog.setMessage(
                    GT.get("Problem"),
                    GT.get("You have reactions in JCP. Reactions cannot be shown as InChI!"));
        } else {
            StringBuffer dialogText = new StringBuffer();
            int i = 0;
            String eol = System.getProperty("line.separator");
            for (IAtomContainer container : model.getMoleculeSet()
                    .atomContainers()) {
                if (model.getMoleculeSet().getAtomContainerCount() > 1) {
                    dialogText.append(GT.get("Structure") + " #" + (i + 1)
                            + eol);
                }
                try {
                    InChI inchi = InChITool.generateInchi(container);
View Full Code Here

     * @return chemModel with molecule set with molecule(s) created using InChI
     * @throws org.openscience.cdk.exception.CDKException
     */
    public static IChemModel readInChI(URL url) throws CDKException {

        IChemModel chemModel = new ChemModel();
        try {
            IAtomContainerSet moleculeSet = new AtomContainerSet();
            chemModel.setMoleculeSet(moleculeSet);
            StdInChIParser parser = new StdInChIParser();

            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = in.readLine()) != null)
View Full Code Here

TOP

Related Classes of org.openscience.cdk.ChemModel

Copyright © 2018 www.massapicom. 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.