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
| class ChangeAtomSymbol extends AbstractUndoableEdit { | |
| IAtomContainer container; | |
| IAtom remove, replace; | |
| ChangeAtomSymbol(IAtomContainer container, | |
| IAtom original, | |
| String newSymbol) { | |
| Atom copy = new Atom(original); // do not clone! |
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
| // check for wide labels | |
| boolean blunt = bounds.getWidth() / bounds.getHeight() > 3; | |
| // ... | |
| return new RoundRectangle2D.Double(x - (width/2), y - (height/2), | |
| width, height, | |
| blunt ? height : width, height); |
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 double[] transformPointDouble(double xCoord, double yCoord) { | |
| double[] src = new double[] {xCoord, yCoord}; | |
| double[] dest = new double[2]; | |
| this.transform.transform(src, 0, dest, 0, 1); | |
| return dest; | |
| } | |
| // ... used in the bounds calculation | |
| double[] p = this.transformPointDouble(x, y); |
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
| class CustomChemObjectBuilder implements IChemObjectBuilder { | |
| private final DynamicFactory factory = new DynamicFactory(200); | |
| public CustomChemObjectBuilder() { | |
| // basic registration | |
| factory.register(Element.class); // discovers Element is an instance of IElement, alternatively... | |
| factory.register(IElement.class, Element.class); // registers Element with IElement explicitly |
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 builder = SilentChemObjectBuilder.getInstance(); | |
| SmilesParser parser = new SmilesParser(builder); | |
| IAtomContainer sodiumChloride = parser.parseSmiles("[Na+].[Cl-]"); | |
| IAtomContainer adenine = parser.parseSmiles("n1c(c2c(nc1)ncn2)N"); | |
| // if you want the separate parts | |
| // import static org.openscience.cdk.graph.ConnectivityChecker.partitionIntoMolecules; | |
| IAtomContainerSet sodiumChlorideSet = partitionIntoMolecules(sodiumChloride); | |
| IAtomContainerSet adenineSet = partitionIntoMolecules(adenine); |
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
| IAtomContainer a = new AtomContainer(); | |
| a.addAtom(new Atom("C")); | |
| a.addAtom(new Atom("C")); | |
| a.addBond(new Bond(a.getAtom(0), a.getAtom(1), SINGLE)); | |
| // copy constructor | |
| IAtomContainer b = new AtomContainer(a); | |
| b.removeAtom(0); // atom at index 0 is removed from b, a is not affected | |
| b.getBond(0).setOrder(DOUBLE); // bond order is change in both a and 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
| public class AdjacencyList implements Graph { | |
| private final int[][] vertexes; | |
| private final IAtom[] atoms; | |
| private final int n; | |
| public AdjacencyList(final IAtomContainer container) { | |
| this.n = container.getAtomCount(); |
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
| private int iterate(IAtomContainer container) { | |
| int total = 0; | |
| for (int d = 0; d < 8; d++) { | |
| for (IAtom atom : container.atoms()) { | |
| for (IBond bond : container.getConnectedBondsList(atom)) { | |
| IAtom other = bond.getConnectedAtom(atom); | |
| total += other.getAtomicNumber(); | |
| } | |
| } | |
| } |
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 int rotate(int value, int n){ | |
| for(int i = 0; i < n; i++) | |
| value = nextInt(value); | |
| return value; | |
| } | |
| public int nextInt(int seed){ | |
| // return pseudo random number from the given seed | |
| } |
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 int rotate(int value, int n){ | |
| for(int i = 0; i < n; i++) | |
| value = nextInt(value); | |
| return value; | |
| } | |
| public int nextInt(int seed){ | |
| // return pseudo random number from the given seed | |
| } |