CxSmilesParser { static int processCx(final String str, final CxSmilesState state) { final CharIter iter = new CharIter(str); if (!iter.nextIf('|')) return -1; while (iter.hasNext()) { switch (iter.next()) { case '$': Map<Integer, String> dest; if (iter.nextIf("_AV:")) dest = state.atomValues = new TreeMap<>(); else dest = state.atomLabels = new TreeMap<>(); if (!processAtomLabels(iter, dest)) return -1; break; case '(': if (!processCoords(iter, state)) return -1; break; case 'c': case 't': if (iter.nextIf(':')) { if (!skipIntList(iter, COMMA_SEPARATOR)) return -1; } else if (iter.nextIf("tu:")) { if (!skipIntList(iter, COMMA_SEPARATOR)) return -1; } break; case 'r': if (iter.nextIf(':')) { if (!skipIntList(iter, COMMA_SEPARATOR)) return -1; } else { if (!iter.nextIf(',') && iter.curr() != '|') return -1; } break; case 'l': if (!iter.nextIf("p:")) return -1; if (!skipIntMap(iter)) return -1; break; case 'f': if (!iter.nextIf(':')) return -1; if (!processFragmentGrouping(iter, state)) return -1; break; case 'S': if (iter.nextIf("g:")) { if (!processPolymerSgroups(iter, state)) return -1; } else if (iter.nextIf("gD:")) { if (!processDataSgroups(iter, state)) return -1; if (iter.nextIf(',')) break; } else if (iter.nextIf("gH:")) { if (!processSgroupsHierarchy(iter, state)) return -1; } else { return -1; } break; case 'm': if (!iter.nextIf(':')) return -1; if (!processPositionalVariation(iter, state)) return -1; break; case '^': if (!processRadicals(iter, state)) return -1; break; case 'C': case 'H': if (!iter.nextIf(':')) return -1; while (iter.hasNext() && isDigit(iter.curr())) { if (!skipIntList(iter, DOT_SEPARATOR)) return -1; iter.nextIf(','); } break; case '|': if (!iter.nextIf(' ')) iter.nextIf('\t'); return iter.pos; case 'L': if (iter.nextIf('O')) { if (!iter.nextIf(':')) return -1; if (!processLigandOrdering(iter, state)) return -1; } else { return -1; } break; default: return -1; } } return -1; } private  CxSmilesParser();   }
@Test public void atomLabels() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|$;;;Het;;;;;A$|", state), is(not(-1))); assertThat(state.atomLabels, hasEntry(3, "Het")); assertThat(state.atomLabels, hasEntry(8, "A")); }
@Test public void escapedAtomLabels() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|$R&#39;;;;;;;$|", state), is(not(-1))); assertThat(state.atomLabels, hasEntry(0, "R'")); }
@Test public void escapedAtomLabels2() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|$;;;&#40;C&#40;R41&#41;&#40;R41&#41;&#41;n;;R41;R41;R41;;_AP1;R41;R41;;_AP1$|", state), is(not(-1))); assertThat(state.atomLabels, hasEntry(3, "(C(R41)(R41))n")); }
@Test public void atomValues() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|$_AV:;;;5;;;;;8$|", state), is(not(-1))); assertThat(state.atomValues, hasEntry(3, "5")); assertThat(state.atomValues, hasEntry(8, "8")); }
@Test public void atomLabelsEmpty() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|$$|", state), is(not(-1))); assertThat(state.atomLabels.size(), is(0)); }
@Test public void atomLabelsTruncated1() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|$;;;Het", state), is(-1)); assertThat(CxSmilesParser.processCx("|$;;;Het;", state), is(-1)); }
@Test public void atomLabelsTruncated3() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|$;;;Het;$", state), is(-1)); }
@Test public void removeUnderscore() { CxSmilesState state = new CxSmilesState(); CxSmilesParser.processCx("|$;;;_R1;$|", state); assertThat(state.atomLabels.get(3), is("R1")); }
@Test public void skipCis() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|c:1,4,5|", state), is(not(-1))); }
@Test public void skipTrans() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|t:1,4,5|", state), is(not(-1))); }
@Test public void skipCisTrans() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|c:2,6,8,t:1,4,5|", state), is(not(-1))); }
@Test public void skipCisTransUnspec() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|c:2,6,8,ctu:10,t:1,4,5|", state), is(not(-1))); }
@Test public void skipLonePairDefinitions() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|c:6,8,t:4,lp:2:2,4:1,11:1,m:1:8.9|", state), is(not(-1))); }
@Test public void fragmentGrouping() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|f:0.1.2.3,4.5.6|", state), is(not(-1))); assertThat(state.fragGroups, is(Arrays.asList(Arrays.asList(0, 1, 2, 3), Arrays.asList(4, 5, 6)))); }
@Test public void fragmentGroupingFollowedByAtomLabels() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|f:0.1.2.3,4.5.6,$;;;R$|", state), is(not(-1))); assertThat(state.fragGroups, is(Arrays.asList(Arrays.asList(0, 1, 2, 3), Arrays.asList(4, 5, 6)))); assertThat(state.atomLabels, hasEntry(3, "R")); }
@Test public void coords() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|(.0,-1.5,;-1.3,-.75,;-2.6,-1.5,;-3.9,-.75,;-3.9,.75,)|", state), is(not(-1))); assertThat(state.atomCoords.get(0), new AprxDoubleArray(0, -1.5, 0)); assertThat(state.atomCoords.get(1), new AprxDoubleArray(-1.3, -.75, 0)); assertThat(state.atomCoords.get(2), new AprxDoubleArray(-2.6, -1.5, 0)); assertThat(state.atomCoords.get(3), new AprxDoubleArray(-3.9, -.75, 0)); assertThat(state.atomCoords.get(4), new AprxDoubleArray(-3.9, .75, 0)); }
@Test public void hydrogenBondingSkipped() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|H:0.1,2.3|", state), is(not(-1))); }
@Test public void hydrogenBondingTruncated() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|H:0.1,2.3", state), is(-1)); assertThat(CxSmilesParser.processCx("|H:0.1,2.", state), is(-1)); }
@Test public void hydrogenAndCoordinationBondingSkipped() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|H:0.1,2.3,C:6.7,3.4|", state), is(not(-1))); }
@Test public void positionalVariation() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|m:2:5.6.7.8.9.10,m:4:5.6.7.8.9|", state), is(not(-1))); assertThat(state.positionVar, hasEntry(2, Arrays.asList(5,6,7,8,9,10))); assertThat(state.positionVar, hasEntry(4, Arrays.asList(5,6,7,8,9))); }
@Test public void positionalVariationImpliedLayer() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|m:2:5.6.7.8.9.10,4:5.6.7.8.9|", state), is(not(-1))); assertThat(state.positionVar, hasEntry(2, Arrays.asList(5,6,7,8,9,10))); assertThat(state.positionVar, hasEntry(4, Arrays.asList(5,6,7,8,9))); }
@Test public void multiAtomSRU() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|Sg:n:1,2,3:m:ht|", state), is(not(-1))); assertThat(state.mysgroups, hasItem(new CxSmilesState.CxPolymerSgroup("n", Arrays.asList(1, 2, 3), "m", "ht"))); }
@Test public void dataSgroups() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|SgD::cdk&#58;ReactionConditions:Heat&#10;Hv|", state), is(not(-1))); assertThat(state.mysgroups, hasItem(new CxSmilesState.CxDataSgroup(new ArrayList<Integer>(), "cdk:ReactionConditions", "Heat\nHv", "", "", ""))); }
@Test public void relativeStereoMolecule() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|r|", state), is(not(-1))); assertThat(CxSmilesParser.processCx("|r,$_R1$|", state), is(not(-1))); assertThat(CxSmilesParser.processCx("|$_R1$,r|", state), is(not(-1))); }
@Test public void relativeStereoReaction() { CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx("|r:2,4,5|", state), is(not(-1))); }
@Test public void sgroupHierarchy() { String cxsmilayers = "|Sg:c:0,1,2,3,4,5,6::,Sg:c:7,8::,Sg:c:9::,Sg:mix:0,1,2,3,4,5,6,7,8,9::,Sg:mix:7,8,9::,SgH:3:4.0,4:2.1|"; CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx(cxsmilayers, state), is(not(-1))); }
@Test public void cxSmiLay() { String cxsmilayers = "|Sg:c:0,1,2,3,4,5,6::,Sg:c:7,8::,Sg:c:9::,Sg:mix:0,1,2,3,4,5,6,7,8,9::,Sg:mix:7,8,9::,SgD::RATIO:1/3::,SgD::RATIO:2/3::,SgD::WEIGHT_PERCENT:15::%,SgH:3:4.0,0:7,4:2.1,1:5,2:6|"; CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx(cxsmilayers, state), is(not(-1))); }
@Test public void cxSmiLay2() { String cxsmilayers = "|Sg:c:0,1,2::,Sg:c:3::,Sg:mix:0,1,2,3::,SgH:2:1.0|"; CxSmilesState state = new CxSmilesState(); assertThat(CxSmilesParser.processCx(cxsmilayers, state), is(not(-1))); }