Esempio n. 1
0
  public ChemComp getChemComp(String recordName) {
    String name = recordName.toUpperCase().trim();
    InputStream inStream = this.getClass().getResourceAsStream("/chemcomp/" + name + ".cif.gz");

    if (inStream == null) {
      // System.out.println("Could not find chem comp: " + name + " ... using generic Chem Comp");
      // could not find the chem comp definition for this in the jar file
      logger.debug("Getting empty chem comp for " + recordName);
      ChemComp cc = getEmptyChemComp();
      cc.setId(name);
      return cc;
    }

    MMcifParser parser = new SimpleMMcifParser();

    ChemCompConsumer consumer = new ChemCompConsumer();

    // The Consumer builds up the BioJava - structure object.
    // you could also hook in your own and build up you own data model.
    parser.addMMcifConsumer(consumer);

    try {
      parser.parse(new BufferedReader(new InputStreamReader(new GZIPInputStream(inStream))));

      ChemicalComponentDictionary dict = consumer.getDictionary();

      ChemComp chemComp = dict.getChemComp(name);

      return chemComp;
    } catch (IOException e) {
      e.printStackTrace();
    }
    logger.warn("Problem when loading chem comp " + name);
    ChemComp cc = getEmptyChemComp();
    cc.setId(name);
    return cc;
  }
Esempio n. 2
0
  /** {@inheritDoc} */
  public ChemComp getChemComp(String recordName) {

    while (loading.get()) {

      // another thread is still initializing the definitions
      try {
        // wait half a second

        Thread.sleep(500);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    return dict.getChemComp(recordName);
  }