Package org.openscience.cdk.io

Examples of org.openscience.cdk.io.ISimpleChemObjectReader


        // InChI workaround - guessing for InChI results into an INChIReader
        // (this does not work, we'd need an INChIPlainTextReader..)
        // Instead here we use STDInChIReader, to be consistent throughout JCP
        // using the nestedVm based classes.
        try {
          ISimpleChemObjectReader cor=null;
            if(url.endsWith("txt")) {
                chemModel = InChITool.readInChI(fileURL);
            }
            else {
                cor = FileHandler.createReader(fileURL, url,type);
View Full Code Here


     * @throws FileNotFoundException
     */
    public static IChemModel readFromFile(File file, String type, AbstractJChemPaintPanel panel)
            throws CDKException, FileNotFoundException {
        String url = file.toURI().toString();
        ISimpleChemObjectReader cor = null;
        try {
            cor = FileHandler.createReader(file.toURI().toURL(), url, type);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        if (cor instanceof CMLReader)
            cor.setReader(new FileInputStream(file)); // hack
        else
            cor.setReader(new FileReader(file)); // hack

        IChemModel chemModel = JChemPaint.getChemModelFromReader(cor,panel);
        boolean avoidOverlap=true;
        if (cor instanceof RGroupQueryReader)
          avoidOverlap=false;
View Full Code Here

          ext = urlString.substring(i + 1).toLowerCase();
        else
          ext = "mol";
        }

        ISimpleChemObjectReader cor = null;

        try {

          /* ReaderFactory.createReader was used before to find the right reader, but this
           * created problems (when applet shrunk with Yguard) because of the classloader
           * used in the ReaderFactory, runtime errors.
           * Instead, we avoid ReaderFactory and pick the right reader below ourselves. */
         
          Reader input = new BufferedReader(getReader(url));
          FormatFactory formatFactory = new FormatFactory(8192);
          IChemFormat format=formatFactory.guessFormat(input);
         
          if (format!=null) {
            if (format instanceof RGroupQueryFormat ) {
                  cor = new RGroupQueryReader();
              cor.setReader(input);
            }
            else if (format instanceof CMLFormat ) {
              cor = new CMLReader(urlString);
              cor.setReader(url.openStream());
            }
            else if (format instanceof MDLV2000Format ) {
                  cor = new MDLV2000Reader(getReader(url));
              cor.setReader(input);
            }
            // SMILES format is never guessed :(
            //else if (format instanceof SMILESFormat ) {
            //  cor = new SMILESReader(getReader(url));
            //  cor.setReader(input);
View Full Code Here

                jcpPanel.get2DHub().getRenderer().getRenderer2DModel().setZoomFactor(1);
            }
        } else if ("paste".equals(type)) {
            handleSystemClipboard(sysClip);
            Transferable transfer = sysClip.getContents( null );
            ISimpleChemObjectReader reader = null;
            String content=null;
           
            if (supported(transfer, molFlavor) ) {
                StringBuffer sb = new StringBuffer();
              try {
                    //StringBufferInputStream sbis=null;
          //sbis = (StringBufferInputStream) transfer.getTransferData(molFlavor);

                    StringReader sbis=null;
          sbis = (StringReader) transfer.getTransferData(molFlavor);

               
                int x;
                    while((x=sbis.read())!=-1){
                        sb.append((char)x);
                    }
                    reader = new MDLReader(new StringReader(sb.toString()));
        } catch (UnsupportedFlavorException e1) {
          e1.printStackTrace();
        } catch (IOException e1) {
          e1.printStackTrace();
              } catch (Exception e1) {
                  reader = new RGroupQueryReader(new StringReader(sb.toString()));
                }

            } else if (supported(transfer, DataFlavor.stringFlavor) ) {
                try {
                    content = (String) transfer.getTransferData(DataFlavor.stringFlavor);
                    reader = new ReaderFactory().createReader(new StringReader(content));
                    //System.out.println(reader.getClass());
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }

            // if looks like CML - InputStream required. Reader throws error.
            if(content!=null && content.indexOf("cml")>-1) {
                reader = new CMLReader(new ByteArrayInputStream(content.getBytes()));
            }

            IAtomContainer toPaste = null;
            boolean rgrpQuery=false;
            if (reader != null) {
                IAtomContainer readMolecule =
                    chemModel.getBuilder().newInstance(IAtomContainer.class);
                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);

                        }
                  } 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 mol
     * @throws Exception
     */
    public void setMolFile(String mol) throws CDKException {
      
      ISimpleChemObjectReader cor=null;
      IChemModel chemModel = null;

      if (mol.contains("$RGP")) {
        cor= new RGroupQueryReader(new StringReader(mol));
        chemModel=JChemPaint.getChemModelFromReader(cor, theJcpp);
View Full Code Here

TOP

Related Classes of org.openscience.cdk.io.ISimpleChemObjectReader

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.