Package org.openscience.cdk.interfaces

Examples of org.openscience.cdk.interfaces.IAtomContainer


     * Tests triple bond is correctly passed to InChI.
     *
     * @throws Exception
     */
    @Test public void testGetInchiFromEthyne() throws Exception {
        IAtomContainer ac = new AtomContainer();
        IAtom a1 = new Atom("C");
        IAtom a2 = new Atom("C");
        a1.setImplicitHydrogenCount(1);
        a2.setImplicitHydrogenCount(1);
        ac.addAtom(a1);
        ac.addAtom(a2);
        ac.addBond(new Bond(a1, a2, CDKConstants.BONDORDER_TRIPLE));
        Assert.assertEquals(gen.generateInchi(ac).getInChI(), "InChI=1S/C2H2/c1-2/h1-2H");
    }
View Full Code Here


   * @see
   * org.openscience.cdk.controller.IChemModelRelay#addRing(org.openscience
   * .cdk.interfaces.IAtom, int, boolean)
   */
  public IRing addRing(IAtom atom, int ringSize, boolean phantom) {
    IAtomContainer sourceContainer = ChemModelManipulator
        .getRelevantAtomContainer(chemModel, atom);
    IAtomContainer sharedAtoms = atom.getBuilder().newInstance(IAtomContainer.class);
    sharedAtoms.addAtom(atom);

    IRing newRing = createAttachRing(sharedAtoms, ringSize, "C", phantom);
    double bondLength = GeometryTools.getBondLengthAverage(sourceContainer);
    Point2d conAtomsCenter = getConnectedAtomsCenter(sharedAtoms, chemModel);

View Full Code Here

   * @see
   * org.openscience.cdk.controller.IChemModelRelay#addPhenyl(org.openscience
   * .cdk.interfaces.IAtom, boolean)
   */
  public IRing addPhenyl(IAtom atom, boolean phantom) {
    IAtomContainer sourceContainer = ChemModelManipulator
        .getRelevantAtomContainer(chemModel, atom);
    IAtomContainer sharedAtoms = atom.getBuilder().newInstance(IAtomContainer.class);
    sharedAtoms.addAtom(atom);

    // make a benzene ring
    IRing newRing = createAttachRing(sharedAtoms, 6, "C", phantom);
    newRing.getBond(0).setOrder(IBond.Order.DOUBLE);
    newRing.getBond(2).setOrder(IBond.Order.DOUBLE);
View Full Code Here

     * @throws Exception
     */
    @Test public void testGetInchiEandZ12Dichloroethene2D() throws Exception {

        // (E)-1,2-dichloroethene
        IAtomContainer acE = new AtomContainer();
        IAtom a1E = new Atom("C", new Point2d(2.866, -0.250));
        IAtom a2E = new Atom("C", new Point2d(3.732, 0.250));
        IAtom a3E = new Atom("Cl", new Point2d(2.000, 2.500));
        IAtom a4E = new Atom("Cl", new Point2d(4.598, -0.250));
        a1E.setImplicitHydrogenCount(1);
        a2E.setImplicitHydrogenCount(1);
        acE.addAtom(a1E);
        acE.addAtom(a2E);
        acE.addAtom(a3E);
        acE.addAtom(a4E);

        acE.addBond(new Bond(a1E, a2E, CDKConstants.BONDORDER_DOUBLE));
        acE.addBond(new Bond(a1E, a3E, CDKConstants.BONDORDER_SINGLE));
        acE.addBond(new Bond(a2E, a4E, CDKConstants.BONDORDER_SINGLE));
       
        Assert.assertEquals(gen.generateInchi(acE).getInChI(), "InChI=1S/C2H2Cl2/c3-1-2-4/h1-2H/b2-1+");
       
        // (Z)-1,2-dichloroethene
        IAtomContainer acZ = new AtomContainer();
        IAtom a1Z = new Atom("C", new Point2d(2.866, -0.440));
        IAtom a2Z = new Atom("C", new Point2d(3.732, 0.060));
        IAtom a3Z = new Atom("Cl", new Point2d(2.000, 0.060));
        IAtom a4Z = new Atom("Cl", new Point2d(3.732, 1.060));
        a1Z.setImplicitHydrogenCount(1);
        a2Z.setImplicitHydrogenCount(1);
        acZ.addAtom(a1Z);
        acZ.addAtom(a2Z);
        acZ.addAtom(a3Z);
        acZ.addAtom(a4Z);

        acZ.addBond(new Bond(a1Z, a2Z, CDKConstants.BONDORDER_DOUBLE));
        acZ.addBond(new Bond(a1Z, a3Z, CDKConstants.BONDORDER_SINGLE));
        acZ.addBond(new Bond(a2Z, a4Z, CDKConstants.BONDORDER_SINGLE));
       
        Assert.assertEquals(gen.generateInchi(acZ).getInChI(), "InChI=1S/C2H2Cl2/c3-1-2-4/h1-2H/b2-1-");

    }
View Full Code Here

    newRing.addBond(sharedAtoms.getBuilder().newInstance(IBond.class,
        ringAtoms[ringSize - 1], ringAtoms[0], IBond.Order.SINGLE));
    newRing.setAtoms(ringAtoms);
    if (!phantom && getUndoRedoFactory() != null
        && getUndoRedoHandler() != null) {
      IAtomContainer undoRedoContainer = newRing.getBuilder()
          .newInstance(IAtomContainer.class,newRing);
      for (IAtom atom : sharedAtoms.atoms())
        undoRedoContainer.removeAtom(atom);
      for (IBond bond : sharedAtoms.bonds())
        undoRedoContainer.removeBond(bond);
      IUndoRedoable undoredo = getUndoRedoFactory()
          .getAddAtomsAndBondsEdit(getIChemModel(),
              undoRedoContainer, null, "Ring" + " " + ringSize,
              this);
      getUndoRedoHandler().postEdit(undoredo);
View Full Code Here

   *            The Atoms the attached partners are searched of
   * @return The Center Point of all the atoms found
   */
  private Point2d getConnectedAtomsCenter(IAtomContainer sharedAtoms,
      IChemModel chemModel) {
    IAtomContainer conAtoms = sharedAtoms.getBuilder().newInstance(IAtomContainer.class);
    for (IAtom sharedAtom : sharedAtoms.atoms()) {
      conAtoms.addAtom(sharedAtom);
      IAtomContainer atomCon = ChemModelManipulator
          .getRelevantAtomContainer(chemModel, sharedAtom);
      for (IAtom atom : atomCon.getConnectedAtomsList(sharedAtom)) {
        conAtoms.addAtom(atom);
      }
    }
    return GeometryTools.get2DCenter(conAtoms);
  }
View Full Code Here

   * @see
   * org.openscience.cdk.controller.IChemModelRelay#addRing(org.openscience
   * .cdk.interfaces.IBond, int, boolean)
   */
  public IRing addRing(IBond bond, int size, boolean phantom) {
    IAtomContainer sharedAtoms = bond.getBuilder().newInstance(IAtomContainer.class);
    IAtom firstAtom = bond.getAtom(0); // Assumes two-atom bonds only
    IAtom secondAtom = bond.getAtom(1);
    sharedAtoms.addAtom(firstAtom);
    sharedAtoms.addAtom(secondAtom);
    sharedAtoms.addBond(bond);
    IAtomContainer sourceContainer = ChemModelManipulator
        .getRelevantAtomContainer(chemModel, firstAtom);

    Point2d sharedAtomsCenter = GeometryTools.get2DCenter(sharedAtoms);

    // calculate two points that are perpendicular to the highlighted bond
    // and have a certain distance from the bond center
    Point2d firstPoint = firstAtom.getPoint2d();
    Point2d secondPoint = secondAtom.getPoint2d();
    Vector2d diff = new Vector2d(secondPoint);
    diff.sub(firstPoint);
    double bondLength = firstPoint.distance(secondPoint);
    double angle = GeometryTools.getAngle(diff.x, diff.y);
    Point2d newPoint1 = new Point2d( // FIXME: what is this point??
        (Math.cos(angle + (Math.PI / 2)) * bondLength / 4)
            + sharedAtomsCenter.x, (Math.sin(angle + (Math.PI / 2))
            * bondLength / 4)
            + sharedAtomsCenter.y);
    Point2d newPoint2 = new Point2d( // FIXME: what is this point??
        (Math.cos(angle - (Math.PI / 2)) * bondLength / 4)
            + sharedAtomsCenter.x, (Math.sin(angle - (Math.PI / 2))
            * bondLength / 4)
            + sharedAtomsCenter.y);

    // decide on which side to draw the ring??
    IAtomContainer connectedAtoms = bond.getBuilder().newInstance(IAtomContainer.class);
    for (IAtom atom : sourceContainer.getConnectedAtomsList(firstAtom)) {
      if (atom != secondAtom)
        connectedAtoms.addAtom(atom);
    }
    for (IAtom atom : sourceContainer.getConnectedAtomsList(secondAtom)) {
      if (atom != firstAtom)
        connectedAtoms.addAtom(atom);
    }
    Point2d conAtomsCenter = GeometryTools.get2DCenter(connectedAtoms);
    double distance1 = newPoint1.distance(conAtomsCenter);
    double distance2 = newPoint2.distance(conAtomsCenter);
    Vector2d ringCenterVector = new Vector2d(sharedAtomsCenter);
View Full Code Here

                File dir = file.listFiles()[i];
                for(int k=0;k<dir.list().length;k++){
                    if(dir.listFiles()[k].getName().indexOf(".mol")>-1){
                        System.err.println(dir.listFiles()[k].getAbsolutePath());
                        MDLV2000Reader reader = new MDLV2000Reader(new FileInputStream(dir.listFiles()[k]), Mode.RELAXED);
                        IAtomContainer cdkmol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
                        String inputstr = getMolSvg(cdkmol, 100, 100);
                        ImageTranscoder imageTranscoder = new JPEGTranscoder();
                        imageTranscoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(.8));
                        TranscoderInput input = new TranscoderInput(new StringReader(inputstr));
                        FileOutputStream ostream = new FileOutputStream(new File(dir.listFiles()[k].getAbsolutePath().substring(0,dir.listFiles()[k].getAbsolutePath().length()-4)+".png"));
View Full Code Here

                File dir = file.listFiles()[i];
                for(int k=0;k<dir.list().length;k++){
                    if(dir.listFiles()[k].getName().indexOf(".mol")>-1){
                        System.err.println(dir.listFiles()[k].getAbsolutePath());
                        MDLV2000Reader reader = new MDLV2000Reader(new FileInputStream(dir.listFiles()[k]), Mode.RELAXED);
                        IAtomContainer cdkmol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
                        String inputstr = getMolSvg(cdkmol, 100, 100);
                        ImageTranscoder imageTranscoder = new JPEGTranscoder();
                        imageTranscoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(.8));
                        TranscoderInput input = new TranscoderInput(new StringReader(inputstr));
                        FileOutputStream ostream = new FileOutputStream(new File(dir.listFiles()[k].getAbsolutePath().substring(0,dir.listFiles()[k].getAbsolutePath().length()-4)+".png"));
View Full Code Here

  public void actionPerformed(ActionEvent event) {
    IChemObject object = getSource(event);
    logger.debug("Showing object properties for: ", object);
    ChemObjectEditor editor = new AtomContainerEditor();
    IAtomContainer relevantContainer = null;
    if(object instanceof IAtom)
      relevantContainer = ChemModelManipulator.getRelevantAtomContainer(jcpPanel.getChemModel(),(IAtom)object);
    if(object instanceof IBond)
      relevantContainer = ChemModelManipulator.getRelevantAtomContainer(jcpPanel.getChemModel(),(IBond)object);
    editor.setChemObject(relevantContainer);
View Full Code Here

TOP

Related Classes of org.openscience.cdk.interfaces.IAtomContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.