Skip to content

Commit ed0759c

Browse files
committed
Params should be set on reaction type, clean up code.
1 parent 2f3eee2 commit ed0759c

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

base/reaction/src/main/java/org/openscience/cdk/reaction/type/PiBondingMovementReaction.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,16 @@ public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agen
133133
// }
134134

135135
AllRingsFinder arf = new AllRingsFinder();
136-
IRingSet ringSet = arf.findAllRings((IAtomContainer) reactant);
136+
IRingSet ringSet = arf.findAllRings(reactant);
137137
for (int ir = 0; ir < ringSet.getAtomContainerCount(); ir++) {
138138
IRing ring = (IRing) ringSet.getAtomContainer(ir);
139139

140140
//only rings with even number of atoms
141141
int nrAtoms = ring.getAtomCount();
142142
if (nrAtoms % 2 == 0) {
143143
int nrSingleBonds = 0;
144-
Iterator<IBond> bondrs = ring.bonds().iterator();
145-
while (bondrs.hasNext()) {
146-
if (bondrs.next().getOrder() == IBond.Order.SINGLE) nrSingleBonds++;
144+
for (IBond iBond : ring.bonds()) {
145+
if (iBond.getOrder() == IBond.Order.SINGLE) nrSingleBonds++;
147146
}
148147
//if exactly half (nrAtoms/2==nrSingleBonds)
149148
if (nrSingleBonds != 0 && nrAtoms / 2 == nrSingleBonds) {
@@ -164,14 +163,12 @@ public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agen
164163

165164
IAtomContainer reactantCloned;
166165
try {
167-
reactantCloned = (IAtomContainer) reactant.clone();
166+
reactantCloned = reactant.clone();
168167
} catch (CloneNotSupportedException e) {
169168
throw new CDKException("Could not clone IAtomContainer!", e);
170169
}
171170

172-
Iterator<IBond> bondis = ring.bonds().iterator();
173-
while (bondis.hasNext()) {
174-
IBond bondi = bondis.next();
171+
for (IBond bondi : ring.bonds()) {
175172
int bondiP = reactant.indexOf(bondi);
176173
if (bondi.getOrder() == IBond.Order.SINGLE)
177174
BondManipulator.increaseBondOrder(reactantCloned.getBond(bondiP));
@@ -180,7 +177,7 @@ public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agen
180177

181178
}
182179

183-
reaction.addProduct((IAtomContainer) reactantCloned);
180+
reaction.addProduct(reactantCloned);
184181
setOfReactions.addReaction(reaction);
185182
}
186183

@@ -198,7 +195,6 @@ public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agen
198195
* FIXME REACT: It could be possible that a ring is a super ring of others small rings
199196
*
200197
* @param reactant The molecule to set the activity
201-
* @throws CDKException
202198
*/
203199
private void setActiveCenters(IAtomContainer reactant) throws CDKException {
204200
AllRingsFinder arf = new AllRingsFinder();
@@ -209,15 +205,13 @@ private void setActiveCenters(IAtomContainer reactant) throws CDKException {
209205
int nrAtoms = ring.getAtomCount();
210206
if (nrAtoms % 2 == 0) {
211207
int nrSingleBonds = 0;
212-
Iterator<IBond> bondrs = ring.bonds().iterator();
213-
while (bondrs.hasNext()) {
214-
if (bondrs.next().getOrder() == IBond.Order.SINGLE) nrSingleBonds++;
208+
for (IBond iBond : ring.bonds()) {
209+
if (iBond.getOrder() == IBond.Order.SINGLE) nrSingleBonds++;
215210
}
216211
//if exactly half (nrAtoms/2==nrSingleBonds)
217212
if (nrSingleBonds != 0 && nrAtoms / 2 == nrSingleBonds) {
218-
Iterator<IBond> bondfs = ring.bonds().iterator();
219-
while (bondfs.hasNext())
220-
bondfs.next().setFlag(CDKConstants.REACTIVE_CENTER, true);
213+
for (IBond iBond : ring.bonds())
214+
iBond.setFlag(CDKConstants.REACTIVE_CENTER, true);
221215

222216
}
223217
}

base/reaction/src/test/java/org/openscience/cdk/reaction/type/PiBondingMovementReactionTest.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public PiBondingMovementReactionTest() throws Exception {
6767
* The JUnit setup method
6868
*/
6969
@Test
70-
public void testPiBondingMovementReaction() throws Exception {
70+
public void testPiBondingMovementReaction() {
7171
IReactionProcess type = new PiBondingMovementReaction();
7272
Assert.assertNotNull(type);
7373
}
@@ -78,8 +78,6 @@ public void testPiBondingMovementReaction() throws Exception {
7878
* Automatic search of the center active.
7979
*
8080
* InChI=1/C6H6/c1-2-4-6-5-3-1/h1-6H
81-
*
82-
* @return The test suite
8381
*/
8482
@Test
8583
@Override
@@ -108,7 +106,7 @@ public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception
108106
setOfReactants.addAtomContainer(molecule);
109107

110108
/* initiate */
111-
List<IParameterReact> paramList = new ArrayList<IParameterReact>();
109+
List<IParameterReact> paramList = new ArrayList<>();
112110
IParameterReact param = new SetReactionCenter();
113111
param.setParameter(Boolean.FALSE);
114112
paramList.add(param);
@@ -131,8 +129,6 @@ public void testInitiate_IAtomContainerSet_IAtomContainerSet() throws Exception
131129
* Automatic search of the center active.
132130
*
133131
* InChI=1/C8H10/c1-7-5-3-4-6-8(7)2/h3-6H,1-2H3
134-
*
135-
* @return The test suite
136132
*/
137133
@Test
138134
public void testAutomaticSearchCentreActiveExample1() throws Exception {
@@ -164,10 +160,11 @@ public void testAutomaticSearchCentreActiveExample1() throws Exception {
164160
setOfReactants.addAtomContainer(molecule);
165161

166162
/* initiate */
167-
List<IParameterReact> paramList = new ArrayList<IParameterReact>();
163+
List<IParameterReact> paramList = new ArrayList<>();
168164
IParameterReact param = new SetReactionCenter();
169165
param.setParameter(Boolean.FALSE);
170166
paramList.add(param);
167+
type.setParameterList(paramList);
171168
IReactionSet setOfReactions = type.initiate(setOfReactants, null);
172169

173170
Assert.assertEquals(1, setOfReactions.getReactionCount());
@@ -215,8 +212,6 @@ static boolean matches(IAtomContainer a, IAtomContainer b) throws CDKException {
215212
* Automatic search of the center active.
216213
*
217214
* InChI=1/C11H10/c1-9-6-7-10-4-2-3-5-11(10)8-9/h2-8H,1H3
218-
*
219-
* @return The test suite
220215
*/
221216
@Test
222217
public void testDoubleRingConjugated() throws Exception {
@@ -225,10 +220,11 @@ public void testDoubleRingConjugated() throws Exception {
225220
IAtomContainerSet setOfReactants = getExampleReactants();
226221

227222
/* initiate */
228-
List<IParameterReact> paramList = new ArrayList<IParameterReact>();
223+
List<IParameterReact> paramList = new ArrayList<>();
229224
IParameterReact param = new SetReactionCenter();
230225
param.setParameter(Boolean.FALSE);
231226
paramList.add(param);
227+
type.setParameterList(paramList);
232228
IReactionSet setOfReactions = type.initiate(setOfReactants, null);
233229

234230
Assert.assertEquals(2, setOfReactions.getReactionCount());
@@ -286,7 +282,6 @@ public void testDoubleRingConjugated() throws Exception {
286282
*
287283
* InChI=1/C11H10/c1-9-6-7-10-4-2-3-5-11(10)8-9/h2-8H,1H3
288284
*
289-
* @return The test suite
290285
*/
291286
@Test
292287
public void testDoubleRingConjugated2() throws Exception {
@@ -305,7 +300,7 @@ public void testDoubleRingConjugated2() throws Exception {
305300
molecule.getBond(11).setFlag(CDKConstants.REACTIVE_CENTER, true);
306301

307302
/* initiate */
308-
List<IParameterReact> paramList = new ArrayList<IParameterReact>();
303+
List<IParameterReact> paramList = new ArrayList<>();
309304
IParameterReact param = new SetReactionCenter();
310305
param.setParameter(Boolean.TRUE);
311306
paramList.add(param);
@@ -422,7 +417,6 @@ private IAtomContainerSet getExpectedProducts() {
422417
* Test to recognize if a IAtomContainer matcher correctly identifies the CDKAtomTypes.
423418
*
424419
* @param molecule The IAtomContainer to analyze
425-
* @throws CDKException
426420
*/
427421
private void makeSureAtomTypesAreRecognized(IAtomContainer molecule) throws Exception {
428422

0 commit comments

Comments
 (0)