@Before
 public void setUp() throws Exception {
   // cNH
   IAtom a2 = new Atom("C");
   a2.setImplicitHydrogenCount(0);
   a2.setFlag(CDKConstants.ISAROMATIC, true);
   IAtom a1 = new Atom("N");
   a1.setImplicitHydrogenCount(1);
   this.bond1 = new Bond(a1, a2, Order.DOUBLE);
 }
Ejemplo n.º 2
0
 @Test
 public void methane_Atom() throws Exception {
   IAtom a = new Atom("C");
   a.setImplicitHydrogenCount(4);
   assertThat(new CDKToBeam().toBeamAtom(a).element(), is(Element.Carbon));
   assertThat(new CDKToBeam().toBeamAtom(a).hydrogens(), is(4));
 }
Ejemplo n.º 3
0
 @Test
 public void defaultIsotope() throws Exception {
   IAtom a = new Atom("C");
   a.setImplicitHydrogenCount(0);
   a.setMassNumber(12);
   assertThat(new CDKToBeam().toBeamAtom(a).isotope(), is(-1));
 }
Ejemplo n.º 4
0
 @Test
 public void aromaticAtom() throws Exception {
   IAtom a = new Atom("C");
   a.setImplicitHydrogenCount(0);
   a.setFlag(CDKConstants.ISAROMATIC, true);
   assertTrue(new CDKToBeam().toBeamAtom(a).aromatic());
 }
Ejemplo n.º 5
0
 @Test
 public void water_Atom() throws Exception {
   IAtom a = new Atom("O");
   a.setImplicitHydrogenCount(2);
   assertThat(new CDKToBeam().toBeamAtom(a).element(), is(Element.Oxygen));
   assertThat(new CDKToBeam().toBeamAtom(a).hydrogens(), is(2));
 }
Ejemplo n.º 6
0
 @Test
 public void chargedAtom() throws Exception {
   IAtom a = new Atom("C");
   a.setImplicitHydrogenCount(0);
   for (int chg = -10; chg < 10; chg++) {
     a.setFormalCharge(chg);
     assertThat(new CDKToBeam().toBeamAtom(a).charge(), is(chg));
   }
 }
Ejemplo n.º 7
0
  /**
   * Applies the MDL valence model to atoms using the explicit valence (bond order sum) and charge
   * to determine the correct number of implicit hydrogens. The model is not applied if the explicit
   * valence is less than 0 - this is the case when a query bond was read for an atom.
   *
   * @param atom the atom to apply the model to
   * @param explicitValence the explicit valence (bond order sum)
   */
  private void applyMDLValenceModel(IAtom atom, int explicitValence) {

    if (explicitValence < 0) return;

    if (atom.getValency() != null) {
      atom.setImplicitHydrogenCount(atom.getValency() - explicitValence);
    } else {
      Integer element = atom.getAtomicNumber();
      if (element == null) return;

      Integer charge = atom.getFormalCharge();
      if (charge == null) charge = 0;

      int implicitValence = MDLValence.implicitValence(element, charge, explicitValence);
      atom.setValency(implicitValence);
      atom.setImplicitHydrogenCount(implicitValence - explicitValence);
    }
  }
Ejemplo n.º 8
0
  /** @cdk.inchi InChI=1/C4H5N/c1-2-4-5-3-1/h1-5H */
  @Test
  public void xtestPyrrole() throws Exception {
    IAtomContainer enol = new AtomContainer();

    // atom block
    IAtom atom1 = new Atom(Elements.CARBON);
    atom1.setHybridization(Hybridization.SP2);
    IAtom atom2 = new Atom(Elements.CARBON);
    atom2.setHybridization(Hybridization.SP2);
    IAtom atom3 = new Atom(Elements.CARBON);
    atom3.setHybridization(Hybridization.SP2);
    IAtom atom4 = new Atom(Elements.CARBON);
    atom4.setHybridization(Hybridization.SP2);
    IAtom atom5 = new Atom(Elements.NITROGEN);
    atom5.setHybridization(Hybridization.SP2);
    atom5.setImplicitHydrogenCount(1);

    // bond block
    IBond bond1 = new Bond(atom1, atom2);
    IBond bond2 = new Bond(atom2, atom3);
    IBond bond3 = new Bond(atom3, atom4);
    IBond bond4 = new Bond(atom4, atom5);
    IBond bond5 = new Bond(atom5, atom1);

    enol.addAtom(atom1);
    enol.addAtom(atom2);
    enol.addAtom(atom3);
    enol.addAtom(atom4);
    enol.addAtom(atom5);
    enol.addBond(bond1);
    enol.addBond(bond2);
    enol.addBond(bond3);
    enol.addBond(bond4);
    enol.addBond(bond5);

    // perceive atom types
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(enol);

    // now have the algorithm have a go at it
    enol = fbot.kekuliseAromaticRings(enol);
    Assert.assertNotNull(enol);
    // Assert.assertTrue(fbot.isOK(enol));

    // now check whether it did the right thing
    Assert.assertEquals(CDKConstants.BONDORDER_DOUBLE, enol.getBond(0).getOrder());
    ;
    Assert.assertEquals(CDKConstants.BONDORDER_SINGLE, enol.getBond(1).getOrder());
    ;
    Assert.assertEquals(CDKConstants.BONDORDER_DOUBLE, enol.getBond(2).getOrder());
    ;
    Assert.assertEquals(CDKConstants.BONDORDER_SINGLE, enol.getBond(3).getOrder());
    ;
    Assert.assertEquals(CDKConstants.BONDORDER_SINGLE, enol.getBond(4).getOrder());
    ;
  }
	/**
	 * Clean up chemical model ,removing duplicates empty molecules etc
	 * 
	 * @param chemModel
	 * @param avoidOverlap
	 * @throws CDKException
	 */
	public static void cleanUpChemModel(final IChemModel chemModel,
			final boolean avoidOverlap, final AbstractJChemPaintPanel panel)
			throws CDKException {
		JChemPaint.setReactionIDs(chemModel);
		JChemPaint.replaceReferencesWithClones(chemModel);

		// check the model is not completely empty
		if (ChemModelManipulator.getBondCount(chemModel) == 0
				&& ChemModelManipulator.getAtomCount(chemModel) == 0) {
			throw new CDKException(
					"Structure does not have bonds or atoms. Cannot depict structure.");
		}
		JChemPaint.removeDuplicateAtomContainers(chemModel);
		JChemPaint.checkCoordinates(chemModel);
		JChemPaint.removeEmptyAtomContainers(chemModel);

		if (avoidOverlap) {
			try {
				ControllerHub.avoidOverlap(chemModel);
			} catch (final Exception e) {
				JOptionPane.showMessageDialog(panel,
						GT._("Structure could not be generated"));
				throw new CDKException("Cannot depict structure");
			}
		}

		// We update implicit Hs in any case
		final CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher
				.getInstance(chemModel.getBuilder());
		for (final IAtomContainer container : ChemModelManipulator
				.getAllAtomContainers(chemModel)) {
			for (final IAtom atom : container.atoms()) {
				if (!(atom instanceof IPseudoAtom)) {
					try {
						final IAtomType type = matcher.findMatchingAtomType(
								container, atom);
						if (type != null
								&& type.getFormalNeighbourCount() != null) {
							final int connectedAtomCount = container
									.getConnectedAtomsCount(atom);
							atom.setImplicitHydrogenCount(type
									.getFormalNeighbourCount()
									- connectedAtomCount);
						}
					} catch (final CDKException e) {
						e.printStackTrace();
					}
				}
			}
		}
	}
Ejemplo n.º 10
0
 private void fixCarbonHCount(IAtomContainer mol) {
   /*
    *  the following line are just a quick fix for this
    *  particluar carbon-only molecule until we have a proper
    *  hydrogen count configurator
    */
   double bondCount = 0;
   org.openscience.cdk.interfaces.IAtom atom;
   for (int f = 0; f < mol.getAtomCount(); f++) {
     atom = mol.getAtom(f);
     bondCount = mol.getBondOrderSum(atom);
     int correction =
         (int) bondCount - (atom.getCharge() != null ? atom.getCharge().intValue() : 0);
     if (atom.getSymbol().equals("C")) {
       atom.setImplicitHydrogenCount(4 - correction);
     } else if (atom.getSymbol().equals("N")) {
       atom.setImplicitHydrogenCount(3 - correction);
     }
     if (standAlone) {
       System.out.println("Hydrogen count for atom " + f + ": " + atom.getImplicitHydrogenCount());
     }
   }
 }
Ejemplo n.º 11
0
  /**
   * @return
   * @throws Exception
   */
  public int process() throws Exception {
    if (file == null) throw new Exception("File not assigned! Use -f command line option.");
    if (!file.exists()) throw new FileNotFoundException(file.getAbsolutePath());
    int records_read = 0;
    int records_processed = 0;
    int records_error = 0;

    InputStream in = new FileInputStream(file);
    /**
     * cdk-io module http://ambit.uni-plovdiv.bg:8083/nexus/index.html#nexus-
     * search;classname~IteratingMDLReader
     */
    IteratingSDFReader reader = null;

    SDFWriter writer = new SDFWriter(new OutputStreamWriter(System.out));

    try {

      reader = new IteratingSDFReader(in, DefaultChemObjectBuilder.getInstance());
      LOGGER.log(Level.INFO, String.format("Reading %s", file.getAbsoluteFile()));
      while (reader.hasNext()) {
        /** Note recent versions allow IAtomContainer molecule = reader.next(); */
        Object object = reader.next();
        IAtomContainer molecule = null;
        if (object instanceof IAtomContainer) molecule = (IAtomContainer) object;
        else break;

        records_read++;
        try {
          /** cdk-standard module */
          AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
          // CDKHueckelAromaticityDetector.detectAromaticity(molecule);
          for (IAtom atom : molecule.atoms())
            if (atom.getImplicitHydrogenCount() == null) {
              LOGGER.fine(
                  atom.getSymbol()
                      + "\t"
                      + atom.getAtomTypeName()
                      + "\t"
                      + atom.getImplicitHydrogenCount());
              atom.setImplicitHydrogenCount(0);
            }

          molecule = AtomContainerManipulator.copyAndSuppressedHydrogens(molecule);

          /** Generate SMILES and assign as properties */
          assignSMILES(molecule);
          molecule.setProperty("REACTION", "REACTANT");
          molecule.setProperty("SMIRKS", "");
          /** Apply reactions */
          writer.write(molecule);
          for (int r = 0; r < smirks.length; r++) {
            if (reactions[r] == null) {
              reactions[r] = smrkMan.parse(smirks[r][1]);
            }
            IAtomContainer reactant = molecule.clone();
            if (smrkMan.applyTransformation(reactant, reactions[r])) {
              AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactant);
              reactant.setProperty("REACTION", "PRODUCT OF " + smirks[r][0]);
              reactant.setProperty("SMIRKS", smirks[r][1]);
              try {
                assignSMILES(reactant);
              } catch (Exception x) {
                LOGGER.log(Level.WARNING, x.getMessage());
              }
              writer.write(reactant);
            }
          }
          records_processed++;
          ;
        } catch (Exception x) {
          System.err.println("*");
          records_error++;
          LOGGER.log(
              Level.SEVERE,
              String.format("[Record %d] Error %s\n", records_read, file.getAbsoluteFile()),
              x);
        }
      }
    } catch (Exception x) {
      LOGGER.log(
          Level.SEVERE,
          String.format("[Record %d] Error %s\n", records_read, file.getAbsoluteFile()),
          x);
    } finally {
      try {
        reader.close();
      } catch (Exception x) {
      }
      try {
        writer.close();
      } catch (Exception x) {
      }
    }
    LOGGER.log(
        Level.INFO,
        String.format(
            "[Records read/processed/error %d/%d/%d] %s",
            records_read, records_processed, records_error, file.getAbsoluteFile()));
    return records_read;
  }
Ejemplo n.º 12
0
 @Test
 public void unknownSymbol_Pseudo() throws Exception {
   IAtom a = new PseudoAtom("R1");
   a.setImplicitHydrogenCount(0);
   assertThat(new CDKToBeam().toBeamAtom(a).element(), is(Element.Unknown));
 }
Ejemplo n.º 13
0
 @Test
 public void unspecifiedIsotope() throws Exception {
   IAtom a = new Atom("C");
   a.setImplicitHydrogenCount(0);
   assertThat(new CDKToBeam().toBeamAtom(a).isotope(), is(-1));
 }
Ejemplo n.º 14
0
 @Test
 public void aliphaticAtom() throws Exception {
   IAtom a = new Atom("C");
   a.setImplicitHydrogenCount(0);
   assertFalse(new CDKToBeam().toBeamAtom(a).aromatic());
 }