📄 maxsrcext.java
字号:
|| (--this.pos2 <= this.pmin)) { /* if not (or there is none), */ this.pos1 = -1; return false; } /* all variants are created */ this.pos1 = this.pos2-1; /* place first bond before second */ return true; /* return 'next variant created' */ } /* variant() */ /*------------------------------------------------------------------*/ public int compareTo (Fragment frag) { /* --- compare extension to fragment */ int t1, t2; /* buffers for comparison */ Embedding emb; /* to access an embedding */ if (this.src < frag.src) return -1; /* compare the indices */ if (this.src > frag.src) return +1; /* of the anchor atoms */ emb = frag.list; /* get an underlying embedding */ t1 = this.bonds[ 0 ].type; t2 = emb.bonds[frag.idx].type; if (t1 < t2) return -1; /* compare the types */ if (t1 > t2) return +1; /* of the (first) added bond */ t1 = this.atoms[ 1 ].type; t2 = emb.atoms[frag.dst].type; if (t1 < t2) return -1; /* compare the types */ if (t1 > t2) return +1; /* of the destination atoms */ if (this.dst < frag.dst) return -1; /* compare the indices */ if (this.dst > frag.dst) return +1; /* of the destination atoms */ t1 = (this.size > 0) ? 1 : ((this.size < 0) ? -1 : 0); t2 = (frag.size > 0) ? 1 : ((frag.size < 0) ? -1 : 0); if (t1 > t2) return -1; /* get the extension types */ if (t1 < t2) return +1; /* from the sizes and compare them */ return (this.size <= 0) /* compare ring ext. if necessary */ ? 0 : this.compareRing(frag); } /* compareTo() */ /*------------------------------------------------------------------*/ protected boolean unclosable (Fragment frag) { /* --- check for uncloseable rings */ int i, k, n; /* loop variable, bond counter */ Molecule mol; /* the fragment as a molecule */ Atom a; /* to traverse the atoms */ mol = frag.getAsMolecule(); /* get the fragment as a molecule */ for (i = frag.src; --i >= 0; ) { a = mol.atoms[i]; /* traverse the unextendable atoms */ for (n = 0, k = a.bondcnt; --k >= 0; ) if ((a.bonds[k].type & Bond.RINGBOND) != 0) n++; if (n == 1) return true; /* if there is a single ring bond, */ } /* a ring cannot be closed anymore, */ return false; /* else all rings may be closable */ } /* unclosable() */ /*------------------------------------------------------------------*/ protected int isCanonic (int bdi, int ati, int cnt) { /* --- check prefix words recursively */ int i, k, c, m, r; /* loop variable, atom index, buffer */ Bond b; /* to traverse/access the bonds */ Atom s, d; /* to traverse/access the atoms */ c = (bdi << 2) +1; /* compute index in code word */ for ( ; ati < this.word[c]; ati++) { s = this.atoms[ati]; /* check atoms before current source */ for (i = s.bondcnt; --i >= 0; ) if (s.bonds[i].mark < 0)/* if there is an unmarked bond */ return bdi; /* from an atom with a smaller index, */ } /* the fragment is not canonical */ r = this.size; /* set the default result and */ s = this.atoms[ati]; /* get the current source atom */ for (i = 0; i < s.bondcnt; i++) { b = s.bonds[i]; /* traverse the unmarked bonds */ if (b.mark >= 0) continue; if (b.type < this.word[c+1]) return bdi; /* check the type */ if (b.type > this.word[c+1]) return r; /* of the bond */ d = (b.src != s) ? b.src : b.dst; if (d.type < this.word[c+2]) return bdi; /* check the type */ if (d.type > this.word[c+2]) return r; /* of the dest. atom */ k = m = d.mark; /* note the atom marker and */ if (m < 0) k = cnt; /* get the destination atom index */ if (k < this.word[c+3]) return bdi; /* check the index */ if (k > this.word[c+3]) continue; /* of the dest. atom */ if (bdi >= r-1) return r; /* check bond index */ b.mark = 0; /* mark the matching bond (and atom) */ if (m < 0) { d.mark = k; this.atoms[cnt++] = d; } k = this.isCanonic(bdi+1, ati, cnt); if (m < 0) { d.mark = -1; cnt--; } b.mark = -1; /* unmark bond (and atom) again */ if (k < r) { if (k < this.src) return k; r = k; } } /* evaluate the recursion result */ return r; /* return the overall result */ } /* isCanonic() */ /*------------------------------------------------------------------*/ protected boolean makeCanonic (int bdi, int ati, int cnt) { /* --- construct canonic code word */ int i, k, c, m; /* loop variable, atom index, buffer */ Bond b; /* to traverse/access the bonds */ Atom s, d; /* to traverse/access the atoms */ boolean changed; /* whether code word was changed */ c = (bdi << 2) +1; /* compute index in code word */ if (bdi >= this.size) { /* if full code word is constructed */ i = this.word[c]; this.word[c] = 0; return (i != 0); /* reinstall sentinel and return */ } /* whether code word was changed */ changed = false; /* default: code word is unchanged */ while (true) { /* source atom search loop */ if ((ati > this.word[c]) /* if beyond small enough source */ || (ati >= cnt)) /* or beyond already numbered atoms, */ return false; /* abort the function */ s = this.atoms[ati]; /* traverse possible source atoms */ for (i = s.bondcnt; --i >= 0; ) if (s.bonds[i].mark < 0) break; if (i >= 0) break; /* check for an unmarked bond */ ati++; /* if all bonds are marked, */ } /* go to the next atom */ if (ati < this.word[c]) { /* if source atom has smaller index, */ this.word[c] = ati; /* replace the code word letter */ this.word[c+1] = MAXCODE; /* and invalidate the next entry */ } /* (so that the rest is replaced) */ for (i = 0; i < s.bondcnt; i++) { b = s.bonds[i]; /* traverse the unmarked bonds */ if (b.mark >= 0) continue; if (b.type > this.word[c+1]) return changed; /* compare the bond type */ if (b.type < this.word[c+1]) { this.word[c+1] = b.type;/* set new bond type */ this.word[c+2] = MAXCODE; } /* on change invalidate next entry */ d = (b.src != s) ? b.src : b.dst; if (d.type > this.word[c+2]) return changed; /* compare destination atom type */ if (d.type < this.word[c+2]) { this.word[c+2] = d.type;/* set new destination atom type */ this.word[c+3] = MAXCODE; } /* on change invalidate next entry */ k = m = d.mark; /* note the atom marker and */ if (m < 0) k = cnt; /* get the destination atom index */ if (k > this.word[c+3]) continue; /* compare destination atom index */ if (k < this.word[c+3]) { this.word[c+3] = k; /* set new destination atom index */ this.word[c+4] = MAXCODE; } /* on change invalidate next entry */ b.mark = 0; /* mark the bond (and atom) */ if (m < 0) { d.mark = k; this.atoms[cnt++] = d; } if (this.makeCanonic(bdi+1, ati, cnt)) { this.bonds[bdi] = b; changed = true; } if (m < 0) { d.mark = -1; cnt--; } b.mark = -1; /* recursively construct code word, */ } /* then unmark bond (and atom) again */ return changed; /* return whether bonds were replaced */ } /* makeCanonic() */ /*------------------------------------------------------------------*/ private boolean removable (Bond b) { /* --- check for a removable bond */ int i; /* loop variable */ long rgs, cur; /* ring flags */ Atom s, a; /* to traverse the ring atoms */ Bond r, x = null; /* to traverse the ring bonds */ rgs = b.flags & Bond.RINGS; /* traverse the ring flags */ for (cur = 1; rgs != 0; cur <<= 1) { if ((rgs & cur) == 0) continue; rgs &= ~cur; /* remove the processed ring flag */ r = b; s = r.src; a = r.dst; do { /* loop to collect the ring bonds */ for (i = a.bondcnt; --i >= 0; ) { x = a.bonds[i]; /* traverse the incident bonds */ if (((x.flags & cur) != 0) && (x != r)) break; } /* find the next ring bond and */ r = x; /* remove the current ring flag */ if (--r.mark == FIXED) /* if all ring flags were removed */ return false; /* from a fixed bond, abort */ a = (r.src != a) ? r.src : r.dst; } while (a != s); /* get the next ring atom */ } /* until the ring is closed */ return true; /* return 'bond is removable' */ } /* removable() */ /*------------------------------------------------------------------*/ protected boolean adaptRing (Fragment frag) { /* --- adapt and check ring extension */ int i, k1, k2, n; /* loop variable, indices */ long rgs, cur; /* ring flags */ Molecule mol; /* the fragment as a molecule */ Bond b, x; /* to traverse the bonds */ boolean changed; /* whether fragment was changed */ mol = frag.getAsMolecule(); /* mark rings in the fragment */ mol.markRings(0, this.rgmax, 0); mol.sort(false); /* prepare molecule for processing */ this.init(mol, 0); /* and init. the extension object */ for (i = mol.bondcnt; --i > 0; ) mol.bonds[i].mark = -1; /* unmark all bonds of the fragment */ for (i = mol.atomcnt; --i > 0; ) mol.atoms[i].mark = -1; /* unmark all atoms and then */ mol.atoms[0].mark = 0; /* mark and store the root atom */ this.atoms[0] = mol.atoms[0]; k1 = frag.ris[frag.ris.length-3]; x = mol.bonds[frag.idx]; /* get the first insertion position */ n = mol.bondcnt; /* and the first (corresp.) ring bond */ if (k1 >= 0) { /* if insertion position is known */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -