This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance()); | |
| final DepictionGenerator dg = new DepictionGenerator().withMolTitle(); | |
| dg.depict(Arrays.asList(smipar.parseSmiles("[H]N1C([H])=C([H])C([H])=C1([H]) expl H (C4H5N)"), | |
| smipar.parseSmiles("N1C=CC=C1 impl H (C4H5N)"), | |
| smipar.parseSmiles("[N]1C([H])=C([H])C([H])=C([H])1 expl H rad (C4H4N)"), | |
| smipar.parseSmiles("[N]1C=CC=C1 impl H rad (C4H4N)"), | |
| smipar.parseSmiles("N1[C]=C([H])C([H])=C([H])1 expl H rad (C4H4N)"), | |
| smipar.parseSmiles("N1[C]=CC=C1 impl H rad (C4H4N)")), | |
| 3, 2) | |
| .writeTo("~/hdisplay.png"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Pattern interface should be used for matching rather than SMARTSQueryTool, | |
| // more efficient and easier to use. | |
| Pattern carboxy = SmartsPattern.compile("[Ov2X2H1+0]-[Cv4X3]=[Ov2X1H0]", bldr); | |
| // Mappings object has several utils, we need basics only here | |
| for (int[] mapping : caboxy.matchAll(mol).uniqueAtoms()) { | |
| IAtom hydroxy = mol.getAtom(mapping[0]); | |
| hydroxy.setImplicitHydrogenCount(0); | |
| hydroxy.setFormalCharge(-1); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static int aromStatus(IAtomContainer mol) { | |
| int res = 0; | |
| for (IAtom atom : mol.atoms()) { | |
| if (atom.getImplicitHydrogenCount() == null && atom.getFlag(CDKConstants.ISAROMATIC)) { | |
| // N and P are ambiguous | |
| if (atom.getAtomicNumber() == 7 || atom.getAtomicNumber() == 15) | |
| res = 2; | |
| else if (res < 2) | |
| res = 1; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| BufferedReader brdr = ...; | |
| // create once and reuse | |
| IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance(); | |
| Aromaticity arom = new Aromaticity(ElectronDonation.daylight(), | |
| Cycles.or(Cycles.all(), Cycles.all(6))); | |
| // SMILES, implicit h already present | |
| SmilesParser smipar = new SmilesParser(bldr); | |
| String line; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance(); | |
| SmilesParser smipar = new SmilesParser(bldr); | |
| SmilesGenerator smigen = SmilesGenerator.generic(); | |
| System.out.println(smigen.create(mykekule(smipar.parseSmiles("c1cc2c(cc1)cccc2")))); | |
| System.out.println(smigen.create(mykekule(smipar.parseSmiles("C1=CC2=C(C=C1)C=CC=C2")))); | |
| System.out.println(smigen.create(mykekule(smipar.parseSmiles("C=1C=C2C(=CC=1)C=CC=C2")))); | |
| System.out.println(smigen.create(mykekule(smipar.parseSmiles("C1=CC=2C(C=C1)=CC=CC=2")))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static IAtomContainer mykekule(IAtomContainer org) throws Exception { | |
| final IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance(); | |
| final SmilesParser smipar = new SmilesParser(bldr); | |
| final SmilesGenerator smigen = SmilesGenerator.unique(); | |
| final int n = org.getAtomCount(); | |
| int[] ordering = new int[n]; | |
| // generate a kekule assignment via SMILES and store the output order (a permutation of |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance(); | |
| SmilesParser smipar = new SmilesParser(bldr); | |
| SmilesGenerator smigen = SmilesGenerator.unique(); | |
| System.out.println(smigen.create(smipar.parseSmiles("c1cc2c(cc1)cccc2"))); | |
| System.out.println(smigen.create(smipar.parseSmiles("C1=CC2=C(C=C1)C=CC=C2"))); | |
| System.out.println(smigen.create(smipar.parseSmiles("C=1C=C2C(=CC=1)C=CC=C2"))); | |
| System.out.println(smigen.create(smipar.parseSmiles("C1=CC=2C(C=C1)=CC=CC=2"))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Map<AtomPair,IBond> bondMap = new HashMap<>(); | |
| for (IBond bond : container.bonds()) | |
| bondMap.put(new AtomPair(bond.getAtom(0), bond.getAtom(1)), | |
| bond); | |
| class AtomPair { | |
| IAtom a, b; | |
| AtomPair(IAtom a, IAtom b) { | |
| this.a = a, this.b = b; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // imports can be inlined but excluded for readability | |
| // import javax.script.SimpleScriptContext; | |
| // import java.io.PrintWriter; | |
| public class Main { | |
| public static void main(String[] args) { | |
| new SimpleScriptContext() {{ | |
| new PrintWriter(writer) {{ | |
| println("Hello World!"); | |
| flush(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Main { | |
| public static void main(String[] args) throws Exception { | |
| while(System.out.getClass() | |
| .getMethod("println", String.class) | |
| .invoke(System.out, "Hello world!") != null) { | |
| } | |
| } | |
| } |