⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sln.java

📁 A program to find frequent molecular substructures and discriminative fragments in a database of mol
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------  File    : SLN.java  Contents: SYBYL Line Notation  Authors : Christian Borgelt  History : 16.08.2006 file created from file SLNTokenizer.java----------------------------------------------------------------------*/package moss;import java.io.IOException;/*--------------------------------------------------------------------*/public class SLN extends Notation {/*--------------------------------------------------------------------*/    public SLN ()                 /* --- create an SLN object */   { this.labels = new int[32]; }  /*------------------------------------------------------------------*/  private void skipH (int len) throws IOException  {                             /* --- skip shorthand hydrogens */    if (this.pos >= len) return;/* check for end of description */    char c = this.desc.charAt(this.pos);    if (c != 'H') return;       /* check for shorthand hydrogens */    if (this.pos+1 >= len) { ++this.pos; return; }    c = this.desc.charAt(this.pos+1);    if ((c >= 'a') && (c <= 'z'))      return;                   /* check for non-hydrogen, e.g. Hg */    ++this.pos;                 /* skip the hydrogen */    if ((c >= '1') && (c <= '9')) ++this.pos;  }  /* skipH() */              /* skip hydrogen counter */  /*------------------------------------------------------------------*/  private int getAtom (int len) throws IOException  {                             /* --- get atom in brackets */    int    i, k;                /* loop variable, buffer */    char   c, n;                /* current and next character */    String s;                   /* to traverse the atom names */    int    atom = 0;            /* number/code of an atom */    this.labels[0] = 0;         /* clear the label buffer */    /* --- find the atom number --- */    c = this.desc.charAt(this.pos-1);  /* get the next characters */    n = (this.pos >= len) ? ' ' : this.desc.charAt(this.pos);    if ((n < 'a') || (n > 'z')){/* if one letter atom name */      for (i = Atom.oneLetter.length; --i >= 0; ) {        k = Atom.oneLetter[i];  /* traverse the atom names */        s = Atom.names[k];      /* that have only one letter */        if (c == s.charAt(0)) { atom |= k; break; }      }                         /* try to find a matching name */      if (i < 0) throw new IOException("illegal atom " +c); }    else {                      /* if two letter atom name */      this.pos++;               /* consume the second character */      for (i = 0; ++i < Atom.names.length; ) {        s = Atom.names[i];      /* traverse the atom names */        if ((s.length() > 1)    /* that have two letters */        &&  (c == s.charAt(0)) && (n == s.charAt(1))) {          atom |= i; break; }   /* try to find a matching */      }                         /* two letter atom name */      if (i >= Atom.names.length)        throw new IOException("illegal atom " +c +n);    }                           /* check whether a name was found */    if ((this.pos >= len)       /* check for end of description */    ||  (this.desc.charAt(this.pos) != '[')) {      this.skipH(len); return atom; }    /* --- get a possible label --- */    i = ++this.pos;             /* consume '[' and note the position */    for (k = 0; true; ) {       /* read a possible label */      if (this.pos >= len) throw new IOException("missing \"]\"");      c = this.desc.charAt(this.pos++);      if ((c < '0') || (c > '9')) break;      k = k *10 +c -'0';        /* compute the label value */    }                           /* and add it to the atom code */    if ((this.pos > i+1) && (k <= 0))      throw new IOException("illegal label " +k);    this.labels[0] = k;         /* note the label of the atom */    if (c == ']') {             /* check for end of attributes */      this.skipH(len); return atom; }    if (this.pos <= i+1)        /* if there was no label, */      this.pos--;               /* put back the last character, */    else if ((c != ';')         /* otherwise check for a separator */    &&       (c != ':'))        /* (static ';' or expression ':') */      throw new IOException("missing \";\" after label");    /* --- get a possible charge --- */    k = 0;                      /* initialize the charge */    while (c != ']') {          /* attributes read loop */      if (this.pos >= len) throw new IOException("missing \"]\"");      c = this.desc.charAt(this.pos++);  /* get the next characters */      n = (this.pos < len) ? this.desc.charAt(this.pos) : ' ';      if (c == '+') {           /* if there is a positive charge */        if       (n == '+')                k = +2;        else if ((n >= '1') && (n <= '9')) k = +(n -'0');        else                               k = +1;        break;                  /* get the value of the charge */      }                         /* and abort the loop */      if (c == '-') {           /* if there is a negative charge */        if       (n == '-')                k = -2;        else if ((n >= '1') && (n <= '9')) k = -(n -'0');        else                               k = -1;        break;                  /* get the value of the charge */      }                         /* and abort the loop */      while ((c != ']') && (c != ';')) {        if (this.pos >= len) throw new IOException("missing \"]\"");        c = this.desc.charAt(this.pos++);      }                         /* skip until separator or delimiter */    }    atom |= Atom.codeCharge(k); /* add the charge to the code */    while (c != ']') {          /* while not at end of attributes */      if (this.pos >= len) throw new IOException("missing \"]\"");      c = this.desc.charAt(this.pos++);    }                           /* read the next character */    this.skipH(len);            /* skip shorthand hydrogens */    return atom;                /* return the atom code */  }  /* getAtom() */  /*------------------------------------------------------------------*/  private int getLabel (int len) throws IOException  {                             /* --- get a ref. to a labelled atom */    char c;                     /* current character */    int  lbl = 0;               /* value of the label */    c = (this.pos < len) ? this.desc.charAt(this.pos) : ' ';    if ((c < '1') || (c > '9')) /* check for a digit */      throw new IOException("incomplete label");    do {                        /* process the next digit */      lbl = lbl *10 +c -'0';    /* recompute the label value */      if (++this.pos >= len)    /* if at the end of the label, */        break;                  /* abort the loop */      c = this.desc.charAt(this.pos);    } while ((c >= '0') && (c <= '9'));    return lbl;                 /* return the label value */  }  /* getLabel() */  /*------------------------------------------------------------------*/  public boolean parse (int src) throws IOException  {                             /* --- parse a molecule description */    int  len;                   /* length of string to parse */    char c;                     /* next character */    int  b, i;                  /* bond type, buffer for label */    int  dst;                   /* index of destination atom */    len = this.desc.length();   /* get the length of the description */    dst = -1;                   /* clear the atom index */    b   = Bond.UNKNOWN;         /* and the bond type */    while (true) {              /* parse loop for a branch */      if (this.pos >= len)      /* if at end of description, */        return false;           /* abort indicating no ')' */      c = this.desc.charAt(this.pos++);      switch (c) {              /* get and evaluate next character */        /* -- branches -- */        case ')':               /* if at the end of a branch */          if (b != Bond.UNKNOWN)/* check for a preceding bond */            throw new IOException("unexpected \")\"");          return true;          /* abort indicating a ')' */        case '(':               /* if at the start of a branch */          if ((src < 0) || (b != Bond.UNKNOWN))            throw new IOException("unexpected \"(\"");          if (!this.parse(src)) /* recursively parse the branch */            throw new IOException("\")\" expected");          break;                /* check for a closing ')' */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -