public String perceiveCDKAtomTypes(IMolecule mol)
             throws InvocationTargetException {
     
     ICDKMolecule cdkmol;
     
     try {
         cdkmol = cdk.asCDKMolecule(mol);
     } 
     catch ( BioclipseException e ) {
         e.printStackTrace();
         throw new InvocationTargetException(
                       e, "Error while creating a ICDKMolecule" );
     }
     
     IAtomContainer ac = cdkmol.getAtomContainer();
     CDKAtomTypeMatcher cdkMatcher 
         = CDKAtomTypeMatcher.getInstance(ac.getBuilder());
     
     StringBuffer result = new StringBuffer();
     int i = 1;
     for (IAtom atom : ac.atoms()) {
         IAtomType type = null;
         try {
             type = cdkMatcher.findMatchingAtomType(ac, atom);
         } 
         catch ( CDKException e ) {}
         result.append(i).append(':').append(
             type != null ? type.getAtomTypeName() : "null"
         ).append('\n'); // FIXME: should use NEWLINE here
         i++;
     }
     return result.toString();
 }
Esempio n. 2
0
 public String removeTriple(String subject, String predicate, String object, String wikiURL) {
   String result = null;
   String action = "DELETE";
   try {
     result = updateTriple(subject, predicate, object, wikiURL, action);
   } catch (BioclipseException e) {
     e.printStackTrace();
   }
   return result;
 }
Esempio n. 3
0
  /**
   * Get
   *
   * @param wikiURL
   * @param limit
   * @return resultRDF
   */
  public IRDFStore getRDF(String wikiURL, int limit) {
    String sparqlQuery = null;
    RDFManager myRdfManager = new RDFManager();
    IRDFStore resultRDF = null;

    if (limit == 0) {
      sparqlQuery = "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }";
    } else {
      sparqlQuery =
          "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }" + "LIMIT " + Integer.toString(limit);
    }

    // Make some configurations
    String serviceURL = wikiURL + "Special:SPARQLEndpoint";

    try {
      resultRDF = myRdfManager.sparqlConstructRemote(serviceURL, sparqlQuery, null);
    } catch (BioclipseException e) {
      e.printStackTrace();
    }

    return resultRDF;
  }
Esempio n. 4
0
 public void putRDF(IRDFStore rdfData, String wikiURL) {
   // Create a Manager for SPARQLing the rdfData
   RDFManager myRdfManager = new RDFManager();
   String sparqlInsertTriple;
   String sparqlGetAllTriples = "SELECT ?s ?p ?o WHERE { ?s ?p ?o }";
   try {
     StringMatrix rdfDataMatrix = myRdfManager.sparql(rdfData, sparqlGetAllTriples);
     int mxRowsCnt = rdfDataMatrix.getRowCount();
     System.out.println("mxRowsCnt: " + mxRowsCnt);
     // We skip the first row which just contains column names
     for (int i = 1; i < mxRowsCnt; i++) {
       sparqlInsertTriple = "INSERT INTO <> {\n";
       sparqlInsertTriple +=
           "<"
               + rdfDataMatrix.get(i, 1)
               + "> <"
               + rdfDataMatrix.get(i, 2)
               + "> <"
               + rdfDataMatrix.get(i, 3)
               + "> .\n";
       sparqlInsertTriple += "}\n";
       System.out.println(
           "SPARQL INSERT CODE:\n---------------------------------\n" + sparqlInsertTriple);
       sparql(sparqlInsertTriple, wikiURL);
     }
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (BioclipseException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (CoreException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
    public String perceiveSybylAtomTypes(IMolecule mol)
                        throws InvocationTargetException {
        
        ICDKMolecule cdkmol;
        
        try {
            cdkmol = cdk.asCDKMolecule(mol);
        } 
        catch (BioclipseException e) {
            System.out.println("Error converting cdk10 to cdk");
            e.printStackTrace();
            throw new InvocationTargetException(e);
        }
        
        IAtomContainer ac = cdkmol.getAtomContainer();
        CDKAtomTypeMatcher cdkMatcher 
            = CDKAtomTypeMatcher.getInstance(ac.getBuilder());
        AtomTypeMapper mapper 
            = AtomTypeMapper.getInstance(
                 "org/openscience/cdk/dict/data/cdk-sybyl-mappings.owl" );

        IAtomType[] sybylTypes = new IAtomType[ac.getAtomCount()];
        
        int atomCounter = 0;
        int a=0;
        for (IAtom atom : ac.atoms()) {
            IAtomType type;
            try {
                type = cdkMatcher.findMatchingAtomType(ac, atom);
            } 
            catch (CDKException e) {
                type = null;
            }
            if (type==null) {
//                logger.debug("AT null for atom: " + atom);
                type = atom.getBuilder().newAtomType(atom.getSymbol());
                type.setAtomTypeName("X");
            }
            AtomTypeManipulator.configure(atom, type);
            a++;
        }
        try {
            CDKHueckelAromaticityDetector.detectAromaticity(ac);
//            System.out.println("Arom: " 
//                + CDKHueckelAromaticityDetector.detectAromaticity(ac) );
		    } 
        catch (CDKException e) {
			    logger.debug("Failed to perceive aromaticity: " + e.getMessage());
		    }
        for (IAtom atom : ac.atoms()) {
            String mappedType = mapper.mapAtomType(atom.getAtomTypeName());
            if ("C.2".equals(mappedType)
                    && atom.getFlag(CDKConstants.ISAROMATIC)) {
                mappedType = "C.ar";
            } 
            else if ("N.pl3".equals(mappedType)
                    && atom.getFlag(CDKConstants.ISAROMATIC)) {
                mappedType = "N.ar";
            }
            try {
                sybylTypes[atomCounter] = factory.getAtomType(mappedType);
		        } 
            catch (NoSuchAtomTypeException e) {
                // yes, setting null's here is important
                sybylTypes[atomCounter] = null; 
			      }
            atomCounter++;
        }
        StringBuffer result = new StringBuffer();
        // now that full perception is finished, we can set atom type names:
        for (int i = 0; i < sybylTypes.length; i++) {
            if (sybylTypes[i] != null) {
                ac.getAtom(i).setAtomTypeName(sybylTypes[i].getAtomTypeName());
            } 
            else {
                ac.getAtom(i).setAtomTypeName("X");
            }
            
            result.append(i).append(':').append(ac.getAtom(i).getAtomTypeName())
                  /*.append("\n")*/;

        }
        return result.toString();
    }