StabilizationCharges { public double calculatePositive(IAtomContainer atomContainer, IAtom atom) { if (atom.getFormalCharge() != 1) { return 0.0; } StructureResonanceGenerator gRI = new StructureResonanceGenerator(); List<IReactionProcess> reactionList = gRI.getReactions(); reactionList.add(new HyperconjugationReaction()); gRI.setReactions(reactionList); IAtomContainerSet resonanceS = gRI.getStructures(atomContainer); IAtomContainerSet containerS = gRI.getContainers(atomContainer); if (resonanceS.getAtomContainerCount() < 2) return 0.0; final int positionStart = atomContainer.indexOf(atom); List<Double> result1 = new ArrayList<Double>(); List<Integer> distance1 = new ArrayList<Integer>(); resonanceS.removeAtomContainer(0); for (Iterator<IAtomContainer> itA = resonanceS.atomContainers().iterator(); itA.hasNext();) { final IAtomContainer resonance = itA.next(); if (resonance.getAtomCount() < 2) continue; final ShortestPaths shortestPaths = new ShortestPaths(resonance, resonance.getAtom(positionStart)); PiElectronegativity electronegativity = new PiElectronegativity(); for (Iterator<IAtom> itAtoms = resonance.atoms().iterator(); itAtoms.hasNext();) { IAtom atomP = itAtoms.next(); IAtom atomR = atomContainer.getAtom(resonance.indexOf(atomP)); if (containerS.getAtomContainer(0).contains(atomR)) { electronegativity.setMaxIterations(6); double result = electronegativity.calculatePiElectronegativity(resonance, atomP); result1.add(result); int dis = shortestPaths.distanceTo(atomP); distance1.add(dis); } } } double value = 0.0; double sum = 0.0; Iterator<Integer> itDist = distance1.iterator(); for (Iterator<Double> itElec = result1.iterator(); itElec.hasNext();) { double suM = itElec.next(); if (suM < 0) suM = -1 * suM; sum += suM * Math.pow(0.67, itDist.next().intValue()); } value = sum; return value; } StabilizationCharges(); double calculatePositive(IAtomContainer atomContainer, IAtom atom);  }
@Test @Category(SlowTest.class) public void testCalculatePositive_IAtomContainer_IAtom() throws Exception { StabilizationCharges sc = new StabilizationCharges(); IAtomContainer molecule = builder.newInstance(IAtomContainer.class); molecule.addAtom(new Atom("C")); molecule.addAtom(new Atom("C")); molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.getAtom(1).setFormalCharge(+1); molecule.addAtom(new Atom("C")); molecule.addBond(1, 2, IBond.Order.SINGLE); molecule.addAtom(new Atom("C")); molecule.addBond(2, 3, IBond.Order.DOUBLE); addExplicitHydrogens(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); lpcheck.saturate(molecule); for (int i = 0; i < molecule.getAtomCount(); i++) { if (i == 1) Assert.assertNotSame(0.0, sc.calculatePositive(molecule, molecule.getAtom(i))); else Assert.assertEquals(0.0, sc.calculatePositive(molecule, molecule.getAtom(i)), 0.001); } }