$darkmode
DENOPTIM
FragmenterToolsTest.java
Go to the documentation of this file.
1package denoptim.fragmenter;
2
3import static org.junit.jupiter.api.Assertions.assertEquals;
4import static org.junit.jupiter.api.Assertions.assertFalse;
5import static org.junit.jupiter.api.Assertions.assertTrue;
6
7import java.util.ArrayList;
8import java.util.Arrays;
9import java.util.HashMap;
10import java.util.HashSet;
11import java.util.List;
12import java.util.Map;
13import java.util.Set;
14
15import javax.vecmath.Point3d;
16
17import org.junit.jupiter.api.Test;
18import org.openscience.cdk.Atom;
19import org.openscience.cdk.PseudoAtom;
20import org.openscience.cdk.interfaces.IAtom;
21import org.openscience.cdk.interfaces.IAtomContainer;
22import org.openscience.cdk.interfaces.IBond;
23import org.openscience.cdk.interfaces.IChemObjectBuilder;
24import org.openscience.cdk.silent.SilentChemObjectBuilder;
25import org.openscience.cdk.smiles.SmilesParser;
26
27import denoptim.constants.DENOPTIMConstants;
28import denoptim.graph.APClass;
29import denoptim.graph.Fragment;
30import denoptim.graph.Vertex.BBType;
31import denoptim.programs.fragmenter.CuttingRule;
32import denoptim.programs.fragmenter.FragmenterParameters;
33import denoptim.programs.fragmenter.MatchedBond;
34
39{
40
44 private IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
45
46//-----------------------------------------------------------------------------
47
48 @Test
49 public void testGetMatchingBonds() throws Exception
50 {
51 IAtomContainer mol = builder.newAtomContainer();
52 mol.addAtom(new Atom("H")); // 0
53 mol.addAtom(new Atom("C")); // 1
54 mol.addAtom(new Atom("C")); // 2
55 mol.addAtom(new Atom("O")); // 3
56 mol.addAtom(new Atom("O")); // 4
57 mol.addAtom(new Atom("C")); // 5
58 mol.addAtom(new Atom("S")); // 6
59 mol.addAtom(new Atom("O")); // 7
60 mol.addAtom(new Atom("H")); // 8
61 mol.addAtom(new Atom("O")); // 9
62 mol.addAtom(new Atom("O")); // 10
63 mol.addAtom(new Atom("H")); // 11
64 mol.addAtom(new Atom("H")); // 12
65 mol.addBond(0, 1, IBond.Order.SINGLE);
66 mol.addBond(1, 2, IBond.Order.TRIPLE);
67 mol.addBond(2, 3, IBond.Order.SINGLE);
68 mol.addBond(3, 4, IBond.Order.SINGLE);
69 mol.addBond(4, 5, IBond.Order.SINGLE);
70 mol.addBond(5, 6, IBond.Order.SINGLE);
71 mol.addBond(6, 7, IBond.Order.SINGLE);
72 mol.addBond(7, 8, IBond.Order.SINGLE);
73 mol.addBond(6, 9, IBond.Order.DOUBLE);
74 mol.addBond(6, 10, IBond.Order.DOUBLE);
75 mol.addBond(5, 11, IBond.Order.SINGLE);
76 mol.addBond(5, 12, IBond.Order.SINGLE);
77
78 ArrayList<String> empty = new ArrayList<String>();
79 List<CuttingRule> rules = new ArrayList<CuttingRule>();
80 rules.add(new CuttingRule("RuleC","[#6]","[#8]","-",-1,empty));
81 rules.add(new CuttingRule("RuleA","[#6]","[#6]","#",0,empty));
82 rules.add(new CuttingRule("RuleB","[$([#6]#[#6])]","[#8]","-",1,empty));
83 rules.add(new CuttingRule("RuleD","[#8]","[S]","-",2,empty));
84 Set<String> anyAtomSMARTS = new HashSet<String>();
85 anyAtomSMARTS.add("[$([*;!#1])]");
86
87 Map<String, List<MatchedBond>> matches =
89
90 assertEquals(matches.get("RuleA").size(),2);
91 assertEquals(matches.get("RuleB").size(),1);
92 assertEquals(matches.get("RuleC").size(),2);
93 assertEquals(matches.get("RuleD").size(),1);
94 }
95
96//------------------------------------------------------------------------------
97
110 @Test
111 public void testExploreHapticity() throws Exception
112 {
113 IAtomContainer mol = builder.newAtomContainer();
114 mol.addAtom(new Atom("Ru")); // 0
115 mol.addAtom(new Atom("Fe")); // 1
116 mol.addAtom(new Atom("C")); // 2 A
117 mol.addAtom(new Atom("C")); // 3 A
118 mol.addAtom(new Atom("C")); // 4 A
119 mol.addAtom(new Atom("C")); // 5 B
120 mol.addAtom(new Atom("C")); // 6 B
121 mol.addAtom(new Atom("C")); // 7 B
122 mol.addAtom(new Atom("C")); // 8 B
123 mol.addAtom(new Atom("C")); // 9 C
124 mol.addAtom(new Atom("C")); // 10 C
125 mol.addAtom(new Atom("C")); // 11 D
126 mol.addAtom(new Atom("C")); // 22 D
127 mol.addAtom(new Atom("C")); // 13 D
128 mol.addAtom(new Atom("C")); // 14 D
129 mol.addAtom(new Atom("C")); // 15 D
130 mol.addAtom(new Atom("O")); // 16
131 mol.addAtom(new Atom("O")); // 17
132 mol.addAtom(new Atom("S")); // 18
133 mol.addAtom(new Atom("S")); // 19
134 mol.addBond(0, 1, IBond.Order.SINGLE);
135
136 // A
137 mol.addBond(0, 2, IBond.Order.SINGLE);
138 mol.addBond(0, 3, IBond.Order.SINGLE);
139 mol.addBond(0, 4, IBond.Order.SINGLE);
140 mol.addBond(2, 3, IBond.Order.SINGLE);
141 mol.addBond(3, 4, IBond.Order.SINGLE);
142
143 // C
144 mol.addBond(0, 9, IBond.Order.SINGLE);
145 mol.addBond(0, 10, IBond.Order.SINGLE);
146 mol.addBond(9, 10, IBond.Order.SINGLE);
147
148 // B
149 mol.addBond(1, 5, IBond.Order.SINGLE);
150 mol.addBond(1, 6, IBond.Order.SINGLE);
151 mol.addBond(1, 7, IBond.Order.SINGLE);
152 mol.addBond(1, 8, IBond.Order.SINGLE);
153 mol.addBond(5, 6, IBond.Order.SINGLE);
154 mol.addBond(6, 7, IBond.Order.SINGLE);
155 mol.addBond(7, 8, IBond.Order.SINGLE);
156
157 // D
158 mol.addBond(1, 11, IBond.Order.SINGLE);
159 mol.addBond(1, 12, IBond.Order.SINGLE);
160 mol.addBond(1, 13, IBond.Order.SINGLE);
161 mol.addBond(1, 14, IBond.Order.SINGLE);
162 mol.addBond(1, 15, IBond.Order.SINGLE);
163 mol.addBond(11, 12, IBond.Order.SINGLE);
164 mol.addBond(12, 13, IBond.Order.SINGLE);
165 mol.addBond(13, 14, IBond.Order.SINGLE);
166 mol.addBond(14, 15, IBond.Order.SINGLE);
167
168 // not in hapto
169 mol.addBond(8, 16, IBond.Order.SINGLE);
170 mol.addBond(17, 16, IBond.Order.SINGLE);
171 mol.addBond(15, 18, IBond.Order.SINGLE);
172 mol.addBond(18, 19, IBond.Order.SINGLE);
173
174 ArrayList<IAtom> candidates = new ArrayList<IAtom>();
175 candidates.add(mol.getAtom(2));
176 candidates.add(mol.getAtom(3));
177 candidates.add(mol.getAtom(4));
178 candidates.add(mol.getAtom(5));
179 candidates.add(mol.getAtom(6));
180 candidates.add(mol.getAtom(7));
181 candidates.add(mol.getAtom(8));
182 candidates.add(mol.getAtom(9));
183 candidates.add(mol.getAtom(10));
184 candidates.add(mol.getAtom(11));
185 candidates.add(mol.getAtom(12));
186 candidates.add(mol.getAtom(13));
187 candidates.add(mol.getAtom(14));
188 candidates.add(mol.getAtom(15));
189
190 Set<IAtom> inHapto = FragmenterTools.exploreHapticity(mol.getAtom(2),
191 mol.getAtom(0), candidates, mol);
192 assertEquals(3,inHapto.size());
193 assertTrue(inHapto.contains(mol.getAtom(2)));
194 assertTrue(inHapto.contains(mol.getAtom(3)));
195 assertTrue(inHapto.contains(mol.getAtom(4)));
196
197 inHapto = FragmenterTools.exploreHapticity(mol.getAtom(9),
198 mol.getAtom(0), candidates, mol);
199 assertEquals(2,inHapto.size());
200 assertTrue(inHapto.contains(mol.getAtom(9)));
201 assertTrue(inHapto.contains(mol.getAtom(10)));
202
203 inHapto = FragmenterTools.exploreHapticity(mol.getAtom(8),
204 mol.getAtom(0), candidates, mol);
205 assertEquals(4,inHapto.size());
206 assertTrue(inHapto.contains(mol.getAtom(5)));
207 assertTrue(inHapto.contains(mol.getAtom(6)));
208 assertTrue(inHapto.contains(mol.getAtom(7)));
209 assertTrue(inHapto.contains(mol.getAtom(8)));
210
211 inHapto = FragmenterTools.exploreHapticity(mol.getAtom(11),
212 mol.getAtom(0), candidates, mol);
213 assertEquals(5,inHapto.size());
214 assertTrue(inHapto.contains(mol.getAtom(11)));
215 assertTrue(inHapto.contains(mol.getAtom(12)));
216 assertTrue(inHapto.contains(mol.getAtom(13)));
217 assertTrue(inHapto.contains(mol.getAtom(14)));
218 assertTrue(inHapto.contains(mol.getAtom(15)));
219 }
220
221//------------------------------------------------------------------------------
222
223 @Test
224 public void testExploreConnectivity() throws Exception
225 {
226 IAtomContainer mol = builder.newAtomContainer();
227 mol.addAtom(new Atom("C")); // 0
228 mol.addAtom(new Atom("C")); // 1
229 mol.addAtom(new Atom("C")); // 2
230 mol.addAtom(new Atom("C")); // 3
231 mol.addAtom(new Atom("B")); // 4
232 mol.addAtom(new Atom("H")); // 5
233 mol.addAtom(new Atom("H")); // 6
234 mol.addAtom(new Atom("B")); // 7
235 mol.addAtom(new Atom("O")); // 8
236 mol.addAtom(new Atom("B")); // 9
237 mol.addBond(0, 1, IBond.Order.DOUBLE);
238 mol.addBond(1, 2, IBond.Order.DOUBLE);
239 mol.addBond(2, 3, IBond.Order.DOUBLE);
240 mol.addBond(5, 6, IBond.Order.SINGLE);
241 mol.addBond(7, 4, IBond.Order.SINGLE);
242 mol.addBond(9, 4, IBond.Order.SINGLE);
243
244 Set<IAtom> system = FragmenterTools.exploreConnectivity(mol.getAtom(2),
245 mol);
246 assertEquals(4,system.size());
247 assertTrue(system.contains(mol.getAtom(0)));
248 assertTrue(system.contains(mol.getAtom(1)));
249 assertTrue(system.contains(mol.getAtom(2)));
250 assertTrue(system.contains(mol.getAtom(3)));
251
252 system = FragmenterTools.exploreConnectivity(mol.getAtom(4), mol);
253 assertEquals(3,system.size());
254 assertTrue(system.contains(mol.getAtom(4)));
255 assertTrue(system.contains(mol.getAtom(7)));
256 assertTrue(system.contains(mol.getAtom(9)));
257
258 system = FragmenterTools.exploreConnectivity(mol.getAtom(6),mol);
259 assertEquals(2,system.size());
260 assertTrue(system.contains(mol.getAtom(5)));
261 assertTrue(system.contains(mol.getAtom(6)));
262
263 system = FragmenterTools.exploreConnectivity(mol.getAtom(8),mol);
264 assertEquals(1,system.size());
265 assertTrue(system.contains(mol.getAtom(8)));
266 }
267
268//-----------------------------------------------------------------------------
269
270 @Test
271 public void testFilterFragment() throws Exception
272 {
273 // First test default criteria:
274
275 //Rejection of PseudoAtoms
276 IAtomContainer mol = builder.newAtomContainer();
277 mol.addAtom(new Atom("C"));
278 mol.addAtom(new PseudoAtom("R"));
279 IAtomContainer mol2 = builder.newAtomContainer();
280 mol2.addAtom(new Atom("C"));
281 mol2.addAtom(new PseudoAtom("C"));
282 IAtomContainer mol3 = builder.newAtomContainer();
283 mol3.addAtom(new Atom("C"));
284 mol3.addAtom(new PseudoAtom("R"));
285 IAtomContainer mol4 = builder.newAtomContainer();
286 mol4.addAtom(new Atom("C"));
287 mol4.addAtom(new PseudoAtom("*"));
288 IAtomContainer mol5 = builder.newAtomContainer();
289 mol5.addAtom(new Atom("C"));
290 mol5.addAtom(new PseudoAtom(DENOPTIMConstants.DUMMYATMSYMBOL));
291 FragmenterParameters settings = new FragmenterParameters(); // default
292 Fragment frag1 = new Fragment(mol, BBType.UNDEFINED);
293 Fragment frag2 = new Fragment(mol2, BBType.UNDEFINED);
294 Fragment frag3 = new Fragment(mol3, BBType.UNDEFINED);
295 Fragment frag4 = new Fragment(mol4, BBType.UNDEFINED);
296 Fragment frag5 = new Fragment(mol5, BBType.UNDEFINED);
297 assertFalse(FragmenterTools.filterFragment(frag1, settings));
298 assertFalse(FragmenterTools.filterFragment(frag2, settings));
299 assertFalse(FragmenterTools.filterFragment(frag3, settings));
300 assertFalse(FragmenterTools.filterFragment(frag4, settings));
301 assertTrue(FragmenterTools.filterFragment(frag5, settings));
302
303 // Incomplete fragmentation. i.e., AP vector pointing to an atom
304 mol = builder.newAtomContainer();
305 mol.addAtom(new Atom("C", new Point3d(1,2,3)));
306 mol.addAtom(new Atom("C", new Point3d(3,4,5)));
307 mol.addAtom(new Atom("C", new Point3d(7,8,9)));
308 frag1 = new Fragment(mol, BBType.UNDEFINED);
309 frag1.addAP(0, APClass.make("dummy:0"), new Point3d(3,4,5));
310 frag2 = new Fragment(mol, BBType.UNDEFINED);
311 frag2.addAP(0, APClass.make("dummy:0"), new Point3d(13,14,15));
312 settings = new FragmenterParameters(); // default
313 assertFalse(FragmenterTools.filterFragment(frag1, settings));
314 assertTrue(FragmenterTools.filterFragment(frag2, settings));
315
316 //Weird isotopes
317 mol = builder.newAtomContainer();
318 IAtom c13 = new Atom("C");
319 c13.setMassNumber(13);
320 mol.addAtom(new Atom("C"));
321 mol.addAtom(c13);
322 frag1 = new Fragment(mol, BBType.UNDEFINED);
323 IAtom d2 = new Atom("H");
324 d2.setMassNumber(2);
325 mol2 = builder.newAtomContainer();
326 mol2.addAtom(new Atom("C"));
327 mol2.addAtom(d2);
328 frag2 = new Fragment(mol2, BBType.UNDEFINED);
329 settings = new FragmenterParameters(); // default
330 assertFalse(FragmenterTools.filterFragment(frag1, settings));
331 assertFalse(FragmenterTools.filterFragment(frag2, settings));
332 // Deactivate filtering of isotopes
333 settings = new FragmenterParameters(); // default
334 settings.setRejectWeirdIsotopes(false);
335 assertTrue(FragmenterTools.filterFragment(frag1, settings));
336 assertTrue(FragmenterTools.filterFragment(frag2, settings));
337
338 // After the defaults, now test customizable criteria
339
340 // Reject by element
341 mol = builder.newAtomContainer();
342 mol.addAtom(new Atom("Zn"));
343 mol.addAtom(new Atom("C"));
344 mol.addAtom(new Atom("H"));
345 frag1 = new Fragment(mol, BBType.UNDEFINED);
346 mol2 = builder.newAtomContainer();
347 mol2.addAtom(new Atom("C"));
348 mol2.addAtom(new Atom("O"));
349 frag2 = new Fragment(mol2, BBType.UNDEFINED);
350 settings = new FragmenterParameters();
351 settings.setRejectedElements(new HashSet<>(Arrays.asList("Zn", "O")));
352 assertFalse(FragmenterTools.filterFragment(frag1, settings));
353 assertFalse(FragmenterTools.filterFragment(frag2, settings));
354
355 // Min heavy atom count
356 mol = builder.newAtomContainer();
357 mol.addAtom(new Atom("C"));
358 mol.addAtom(new Atom("C"));
359 mol.addAtom(new Atom("C"));
360 mol.addAtom(new Atom("H"));
361 mol2 = builder.newAtomContainer();
362 mol2.addAtom(new Atom("C"));
363 mol2.addAtom(new Atom("H"));
364 mol2.addAtom(new Atom("H"));
365 mol2.addAtom(new Atom("H"));
366 mol3 = builder.newAtomContainer();
367 mol3.addAtom(new Atom("C"));
368 mol3.addAtom(new Atom("C"));
369 mol3.addAtom(new Atom("C"));
370 mol3.addAtom(new Atom("O"));
371 settings = new FragmenterParameters();
372 settings.setMinFragHeavyAtomCount(2);
373 Fragment fragOK = new Fragment(mol, BBType.UNDEFINED);
374 Fragment fragNO = new Fragment(mol2, BBType.UNDEFINED);
375 assertTrue(FragmenterTools.filterFragment(fragOK, settings));
376 assertFalse(FragmenterTools.filterFragment(fragNO, settings));
377
378 // Max heavy atom count
379 settings = new FragmenterParameters();
380 settings.setMaxFragHeavyAtomCount(2);
381 fragOK = new Fragment(mol2, BBType.UNDEFINED);
382 fragNO = new Fragment(mol, BBType.UNDEFINED);
383 assertTrue(FragmenterTools.filterFragment(fragOK, settings));
384 assertFalse(FragmenterTools.filterFragment(fragNO, settings));
385
386 // Reject by APClass
387 Set<String> apcRejecting = new HashSet<String>();
388 apcRejecting.add("badAP");
389 apcRejecting.add("badO");
390 settings = new FragmenterParameters();
391 settings.setRejectedAPClasses(apcRejecting);
392 fragOK = new Fragment(mol, BBType.UNDEFINED);
393 fragOK.addAP(0, APClass.make("APCgood:0"));
394 fragOK.addAP(1, APClass.make("APCgood:1"));
395 fragOK.addAP(2, APClass.make("BlaBla:0"));
396 fragNO = new Fragment(mol2, BBType.UNDEFINED);
397 fragNO.addAP(0, APClass.make("APCgood:0"));
398 fragNO.addAP(1, APClass.make("APCgood:1"));
399 fragNO.addAP(2, APClass.make("badAPC:0"));
400 fragNO.addAP(3, APClass.make("badAPC:1"));
401 fragNO.addAP(0, APClass.make("badOne:1"));
402 fragNO.addAP(1, APClass.make("BlaBla:0"));
403 assertTrue(FragmenterTools.filterFragment(fragOK, settings));
404 assertFalse(FragmenterTools.filterFragment(fragNO, settings));
405
406 // Reject by APClass combination
407 frag3 = new Fragment(mol3, BBType.UNDEFINED);
408 frag3.addAP(0, APClass.make("APCgood:0"));
409 frag3.addAP(1, APClass.make("bar:2"));
410 frag3.addAP(2, APClass.make("badAPC:0"));
411 frag3.addAP(3, APClass.make("badAPC:1"));
412 frag3.addAP(0, APClass.make("badOne:1"));
413 frag3.addAP(1, APClass.make("foo:0"));
414 frag4 = new Fragment(mol3, BBType.UNDEFINED);
415 frag3.addAP(1, APClass.make("bar:2"));
416 frag3.addAP(2, APClass.make("bad:0"));
417 frag3.addAP(3, APClass.make("BlaBla:1"));
418 frag3.addAP(1, APClass.make("foo:0"));
419 Set<String[]> apcCombRejecting = new HashSet<String[]>();
420 apcCombRejecting.add(new String[] {"badA","Bla"}); //rejects fragNO
421 apcCombRejecting.add(new String[] {"foo","APCgood:0","bar"}); //rejects frag3
422 settings = new FragmenterParameters();
423 settings.setRejectedAPClassCombinations(apcCombRejecting);
424 assertTrue(FragmenterTools.filterFragment(fragOK, settings));
425 assertFalse(FragmenterTools.filterFragment(fragNO, settings));
426 assertFalse(FragmenterTools.filterFragment(frag3, settings));
427 assertTrue(FragmenterTools.filterFragment(frag4, settings));
428
429 //Formula less-than
430 mol = builder.newAtomContainer(); // C6 H6
431 mol.addAtom(new Atom("C"));
432 mol.addAtom(new Atom("C"));
433 mol.addAtom(new Atom("C"));
434 mol.addAtom(new Atom("C"));
435 mol.addAtom(new Atom("C"));
436 mol.addAtom(new Atom("C"));
437 mol.addAtom(new Atom("H"));
438 mol.addAtom(new Atom("H"));
439 mol.addAtom(new Atom("H"));
440 mol.addAtom(new Atom("H"));
441 mol.addAtom(new Atom("H"));
442 mol.addAtom(new Atom("H"));
443 mol2 = builder.newAtomContainer(); // C1 O1 H4
444 mol2.addAtom(new Atom("C"));
445 mol2.addAtom(new Atom("O"));
446 mol2.addAtom(new Atom("H"));
447 mol2.addAtom(new Atom("H"));
448 mol2.addAtom(new Atom("H"));
449 mol2.addAtom(new Atom("H"));
450 mol3 = builder.newAtomContainer(); // C4 O2 H4
451 mol3.addAtom(new Atom("C"));
452 mol3.addAtom(new Atom("C"));
453 mol3.addAtom(new Atom("C"));
454 mol3.addAtom(new Atom("C"));
455 mol3.addAtom(new Atom("O"));
456 mol3.addAtom(new Atom("O"));
457 mol3.addAtom(new Atom("H"));
458 mol3.addAtom(new Atom("H"));
459 mol3.addAtom(new Atom("H"));
460 mol3.addAtom(new Atom("H"));
461 mol4 = builder.newAtomContainer(); // C3 H8
462 mol4.addAtom(new Atom("C"));
463 mol4.addAtom(new Atom("C"));
464 mol4.addAtom(new Atom("C"));
465 mol4.addAtom(new Atom("H"));
466 mol4.addAtom(new Atom("H"));
467 mol4.addAtom(new Atom("H"));
468 mol4.addAtom(new Atom("H"));
469 mol4.addAtom(new Atom("H"));
470 mol4.addAtom(new Atom("H"));
471 mol4.addAtom(new Atom("H"));
472 mol4.addAtom(new Atom("H"));
473 frag1 = new Fragment(mol, BBType.UNDEFINED);
474 frag2 = new Fragment(mol2, BBType.UNDEFINED);
475 frag3 = new Fragment(mol3, BBType.UNDEFINED);
476 frag4 = new Fragment(mol4, BBType.UNDEFINED);
477 settings = new FragmenterParameters();
478 Set<Map<String,Double>> formulaMin = new HashSet<Map<String,Double>>();
479 Map<String,Double> formulaA = new HashMap<String,Double>();
480 formulaA.put("C", 5.0);
481 formulaA.put("H", 6.0);
482 Map<String,Double> formulaB = new HashMap<String,Double>();
483 formulaB.put("O", 1.0);
484 formulaMin.add(formulaA);
485 formulaMin.add(formulaB);
486 settings.setRejectedFormulaMoreThan(formulaMin);
487 assertFalse(FragmenterTools.filterFragment(frag1, settings));
488 assertTrue(FragmenterTools.filterFragment(frag2, settings));
489 assertFalse(FragmenterTools.filterFragment(frag3, settings));
490 assertFalse(FragmenterTools.filterFragment(frag4, settings));
491
492 //Formula more-than
493 Map<String,Double> formulaMax = new HashMap<String,Double>();
494 formulaMax.put("C", 3.0);
495 formulaMax.put("H", 2.0);
496 formulaMax.put("O", 1.0);
497 settings = new FragmenterParameters();
498 settings.setRejectedFormulaLessThan(formulaMax);
499 assertFalse(FragmenterTools.filterFragment(frag1, settings));
500 assertFalse(FragmenterTools.filterFragment(frag2, settings));
501 assertTrue(FragmenterTools.filterFragment(frag3, settings));
502 assertFalse(FragmenterTools.filterFragment(frag4, settings));
503
504 //SMARTS query rejection
505 SmilesParser p = new SmilesParser(builder);
506 mol = p.parseSmiles("c1ccccc1OC");
507 mol2 = p.parseSmiles("CCOOCCl");
508 mol3 = p.parseSmiles("CN(C)CC");
509 mol4 = p.parseSmiles("c1ccccc1N(C)CCCCl");
510 frag1 = new Fragment(mol, BBType.UNDEFINED);
511 frag2 = new Fragment(mol2, BBType.UNDEFINED);
512 frag3 = new Fragment(mol3, BBType.UNDEFINED);
513 frag4 = new Fragment(mol4, BBType.UNDEFINED);
514 Map<String,String> smarts = new HashMap<String,String>();
515 smarts.put("A", "C!@-CO");
516 settings = new FragmenterParameters();
517 settings.setFragRejectionSMARTS(smarts);
518 assertTrue(FragmenterTools.filterFragment(frag1, settings));
519 assertFalse(FragmenterTools.filterFragment(frag2, settings));
520 assertTrue(FragmenterTools.filterFragment(frag3, settings));
521 assertTrue(FragmenterTools.filterFragment(frag4, settings));
522 smarts.put("B", "[#6]O");
523 settings = new FragmenterParameters();
524 settings.setFragRejectionSMARTS(smarts);
525 assertFalse(FragmenterTools.filterFragment(frag1, settings));
526 assertFalse(FragmenterTools.filterFragment(frag2, settings));
527 assertTrue(FragmenterTools.filterFragment(frag3, settings));
528 assertTrue(FragmenterTools.filterFragment(frag4, settings));
529
530 //SMARTS query retention
531 smarts = new HashMap<String,String>();
532 smarts.put("C", "O-O");
533 smarts.put("D", "CCl");
534 settings = new FragmenterParameters();
535 settings.setFragRetentionSMARTS(smarts);
536 assertFalse(FragmenterTools.filterFragment(frag1, settings));
537 assertTrue(FragmenterTools.filterFragment(frag2, settings));
538 assertFalse(FragmenterTools.filterFragment(frag3, settings));
539 assertTrue(FragmenterTools.filterFragment(frag4, settings));
540 }
541
542//------------------------------------------------------------------------------
543
544 @Test
545 public void testGetMWSlotIdentifier() throws Exception
546 {
547 int slotSize = 2;
548 IAtomContainer mol1 = builder.newAtomContainer();
549 mol1.addAtom(new Atom("H"));
550 IAtomContainer mol2 = builder.newAtomContainer();
551 mol2.addAtom(new Atom("H"));
552 mol2.addAtom(new Atom("H"));
553 IAtomContainer mol3 = builder.newAtomContainer();
554 mol3.addAtom(new Atom("H"));
555 mol3.addAtom(new Atom("H"));
556 mol3.addAtom(new Atom("H"));
557 IAtomContainer mol4 = builder.newAtomContainer();
558 mol4.addAtom(new Atom("C"));
559 IAtomContainer mol5 = builder.newAtomContainer();
560 mol5.addAtom(new Atom("C"));
561 mol5.addAtom(new PseudoAtom(DENOPTIMConstants.DUMMYATMSYMBOL));
562 Fragment f1 = new Fragment(mol1, BBType.UNDEFINED);
563 Fragment f2 = new Fragment(mol2, BBType.UNDEFINED);
564 Fragment f3 = new Fragment(mol3, BBType.UNDEFINED);
565 Fragment f4 = new Fragment(mol4, BBType.UNDEFINED);
566 Fragment f5 = new Fragment(mol5, BBType.UNDEFINED);
567 assertEquals("0-2",FragmenterTools.getMWSlotIdentifier(f1, slotSize));
568 assertEquals("2-4",FragmenterTools.getMWSlotIdentifier(f2, slotSize));
569 assertEquals("2-4",FragmenterTools.getMWSlotIdentifier(f3, slotSize));
570 assertEquals("12-14",FragmenterTools.getMWSlotIdentifier(f4, slotSize));
571 assertEquals("12-14",FragmenterTools.getMWSlotIdentifier(f5, slotSize));
572 }
573}
General set of constants used in DENOPTIM.
static final String DUMMYATMSYMBOL
Symbol of dummy atom.
static Map< String, List< MatchedBond > > getMatchingBondsAllInOne(IAtomContainer mol, List< CuttingRule > rules, Logger logger)
Identification of the bonds matching a list of SMARTS queries.
static boolean filterFragment(Fragment frag, FragmenterParameters settings)
Filter fragments according to the criteria defined in the settings.
static Set< IAtom > exploreConnectivity(IAtom seed, IAtomContainer mol)
Explores the connectivity annotating which atoms have been visited.
static Set< IAtom > exploreHapticity(IAtom seed, IAtom centralAtom, ArrayList< IAtom > candidates, IAtomContainer mol)
Identifies non-central atoms involved in the same n-hapto ligand as the seed atom.
static String getMWSlotIdentifier(Vertex frag, int slotSize)
Determines the name of the MW slot to use when comparing the given fragment with previously stored fr...
Unit test for fragmenter's tools.
void testExploreHapticity()
Works on this system.
IChemObjectBuilder builder
Private builder of atom containers.
static APClass make(String ruleAndSubclass)
Creates an APClass if it does not exist already, or returns the reference to the existing instance.
Definition: APClass.java:136
Class representing a continuously connected portion of chemical object holding attachment points.
Definition: Fragment.java:61
void addAP(int atomPositionNumber)
Adds an attachment point with a dummy APClass.
Definition: Fragment.java:343
A cutting rule with three SMARTS queries (atom 1, bond, atom2) and options.
Parameters controlling execution of the fragmenter.
void setFragRejectionSMARTS(Map< String, String > fragRejectionSMARTS)
void setRejectedAPClassCombinations(Set< String[]> rejectedAPClassCombinations)
void setRejectedFormulaMoreThan(Set< Map< String, Double > > formulaCriteriaMoreThan)
void setFragRetentionSMARTS(Map< String, String > fragRetentionSMARTS)
void setRejectedFormulaLessThan(Map< String, Double > formulaMax)
void setRejectWeirdIsotopes(boolean doRejectWeirdIsotopes)
void setRejectedAPClasses(Set< String > rejectedAPClasses)
void setRejectedElements(Set< String > rejectedElements)
The type of building block.
Definition: Vertex.java:86