|
25 | 25 | package org.openscience.cdk.io; |
26 | 26 |
|
27 | 27 | import com.google.common.collect.ImmutableSet; |
| 28 | +import org.openscience.cdk.AtomRef; |
28 | 29 | import org.openscience.cdk.CDKConstants; |
29 | 30 | import org.openscience.cdk.config.Elements; |
30 | 31 | import org.openscience.cdk.config.IsotopeFactory; |
|
48 | 49 | import org.openscience.cdk.io.setting.BooleanIOSetting; |
49 | 50 | import org.openscience.cdk.io.setting.IOSetting; |
50 | 51 | import org.openscience.cdk.isomorphism.matchers.Expr; |
| 52 | +import org.openscience.cdk.isomorphism.matchers.IQueryAtom; |
| 53 | +import org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer; |
| 54 | +import org.openscience.cdk.isomorphism.matchers.IQueryBond; |
| 55 | +import org.openscience.cdk.isomorphism.matchers.QueryAtom; |
51 | 56 | import org.openscience.cdk.isomorphism.matchers.QueryAtomContainer; |
52 | 57 | import org.openscience.cdk.isomorphism.matchers.QueryBond; |
53 | 58 | import org.openscience.cdk.sgroup.Sgroup; |
@@ -430,8 +435,10 @@ private IAtomContainer readAtomContainer(IAtomContainer molecule) throws CDKExce |
430 | 435 | linecount++; |
431 | 436 |
|
432 | 437 | bonds[i] = readBondFast(line, molecule.getBuilder(), atoms, explicitValence, linecount); |
433 | | - hasQueryBonds = hasQueryBonds |
434 | | - || (bonds[i].getOrder() == IBond.Order.UNSET && !bonds[i].getFlag(CDKConstants.ISAROMATIC)); |
| 438 | + hasQueryBonds = hasQueryBonds || |
| 439 | + bonds[i] instanceof IQueryBond || |
| 440 | + (bonds[i].getOrder() == IBond.Order.UNSET && |
| 441 | + !bonds[i].getFlag(CDKConstants.ISAROMATIC)); |
435 | 442 | } |
436 | 443 |
|
437 | 444 | if (!hasQueryBonds) |
@@ -517,7 +524,7 @@ private IAtomContainer readAtomContainer(IAtomContainer molecule) throws CDKExce |
517 | 524 | // sanity check that we have a decent molecule, query bonds mean we |
518 | 525 | // don't have a hydrogen count for atoms and stereo perception isn't |
519 | 526 | // currently possible |
520 | | - if (!hasQueryBonds && addStereoElements.isSet() && hasX && hasY) { |
| 527 | + if (!(outputContainer instanceof IQueryAtomContainer) && addStereoElements.isSet() && hasX && hasY) { |
521 | 528 | if (hasZ) { // has 3D coordinates |
522 | 529 | outputContainer.setStereoElements(StereoElementFactory.using3DCoordinates(outputContainer) |
523 | 530 | .createAll()); |
@@ -896,6 +903,47 @@ void readPropertiesFast(final BufferedReader input, final IAtomContainer contain |
896 | 903 | if (group == null) return; |
897 | 904 | break; |
898 | 905 |
|
| 906 | + // M ALS aaannn e 11112222 ... |
| 907 | + // 012345678901234567 |
| 908 | + // aaa: atom index |
| 909 | + // nnn: count |
| 910 | + // e: T/F(default) exclusion list |
| 911 | + // 1111: symbol |
| 912 | + case M_ALS: |
| 913 | + index = readUInt(line, 7, 3)-1; |
| 914 | + // count = readUInt(line, 10, 3); // not needed |
| 915 | + { |
| 916 | + boolean negate = line.charAt(13) == 'T' || |
| 917 | + line.charAt(14) == 'T'; |
| 918 | + Expr expr = new Expr(Expr.Type.TRUE); |
| 919 | + StringBuilder sb = new StringBuilder(); |
| 920 | + for (int i = 16; i < line.length(); i++) { |
| 921 | + if (line.charAt(i) != ' ') { |
| 922 | + sb.append(line.charAt(i)); |
| 923 | + } else if (sb.length() != 0) { |
| 924 | + int elem = Elements.ofString(sb.toString()).number(); |
| 925 | + if (elem != 0) |
| 926 | + expr.or(new Expr(Expr.Type.ELEMENT, elem)); |
| 927 | + sb.setLength(0); |
| 928 | + } |
| 929 | + } |
| 930 | + if (sb.length() != 0) { |
| 931 | + int elem = Elements.ofString(sb.toString()).number(); |
| 932 | + if (elem != 0) |
| 933 | + expr.or(new Expr(Expr.Type.ELEMENT, elem)); |
| 934 | + } |
| 935 | + if (negate) |
| 936 | + expr.negate(); |
| 937 | + IAtom atom = container.getAtom(index); |
| 938 | + if (AtomRef.deref(atom) instanceof QueryAtom) { |
| 939 | + QueryAtom ref = (QueryAtom)AtomRef.deref(atom); |
| 940 | + ref.setExpression(expr); |
| 941 | + } else { |
| 942 | + container.setAtom(index, new QueryAtom(expr)); |
| 943 | + } |
| 944 | + } |
| 945 | + break; |
| 946 | + |
899 | 947 | // M CHGnn8 aaa vvv ... |
900 | 948 | // |
901 | 949 | // vvv: -15 to +15. Default of 0 = uncharged atom. When present, this property supersedes |
|
0 commit comments