1package denoptim.fragmenter;
3import static org.junit.jupiter.api.Assertions.assertEquals;
4import static org.junit.jupiter.api.Assertions.assertFalse;
5import static org.junit.jupiter.api.Assertions.assertTrue;
7import java.util.ArrayList;
8import java.util.Arrays;
9import java.util.HashMap;
10import java.util.HashSet;
15import javax.vecmath.Point3d;
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;
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;
44 private IChemObjectBuilder
builder = SilentChemObjectBuilder.getInstance();
51 IAtomContainer mol =
builder.newAtomContainer();
52 mol.addAtom(
new Atom(
"H"));
53 mol.addAtom(
new Atom(
"C"));
54 mol.addAtom(
new Atom(
"C"));
55 mol.addAtom(
new Atom(
"O"));
56 mol.addAtom(
new Atom(
"O"));
57 mol.addAtom(
new Atom(
"C"));
58 mol.addAtom(
new Atom(
"S"));
59 mol.addAtom(
new Atom(
"O"));
60 mol.addAtom(
new Atom(
"H"));
61 mol.addAtom(
new Atom(
"O"));
62 mol.addAtom(
new Atom(
"O"));
63 mol.addAtom(
new Atom(
"H"));
64 mol.addAtom(
new Atom(
"H"));
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);
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])]");
87 Map<String, List<MatchedBond>> matches =
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);
113 IAtomContainer mol =
builder.newAtomContainer();
114 mol.addAtom(
new Atom(
"Ru"));
115 mol.addAtom(
new Atom(
"Fe"));
116 mol.addAtom(
new Atom(
"C"));
117 mol.addAtom(
new Atom(
"C"));
118 mol.addAtom(
new Atom(
"C"));
119 mol.addAtom(
new Atom(
"C"));
120 mol.addAtom(
new Atom(
"C"));
121 mol.addAtom(
new Atom(
"C"));
122 mol.addAtom(
new Atom(
"C"));
123 mol.addAtom(
new Atom(
"C"));
124 mol.addAtom(
new Atom(
"C"));
125 mol.addAtom(
new Atom(
"C"));
126 mol.addAtom(
new Atom(
"C"));
127 mol.addAtom(
new Atom(
"C"));
128 mol.addAtom(
new Atom(
"C"));
129 mol.addAtom(
new Atom(
"C"));
130 mol.addAtom(
new Atom(
"O"));
131 mol.addAtom(
new Atom(
"O"));
132 mol.addAtom(
new Atom(
"S"));
133 mol.addAtom(
new Atom(
"S"));
134 mol.addBond(0, 1, IBond.Order.SINGLE);
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);
144 mol.addBond(0, 9, IBond.Order.SINGLE);
145 mol.addBond(0, 10, IBond.Order.SINGLE);
146 mol.addBond(9, 10, IBond.Order.SINGLE);
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);
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);
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);
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));
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)));
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)));
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)));
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)));
226 IAtomContainer mol =
builder.newAtomContainer();
227 mol.addAtom(
new Atom(
"C"));
228 mol.addAtom(
new Atom(
"C"));
229 mol.addAtom(
new Atom(
"C"));
230 mol.addAtom(
new Atom(
"C"));
231 mol.addAtom(
new Atom(
"B"));
232 mol.addAtom(
new Atom(
"H"));
233 mol.addAtom(
new Atom(
"H"));
234 mol.addAtom(
new Atom(
"B"));
235 mol.addAtom(
new Atom(
"O"));
236 mol.addAtom(
new Atom(
"B"));
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);
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)));
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)));
259 assertEquals(2,system.size());
260 assertTrue(system.contains(mol.getAtom(5)));
261 assertTrue(system.contains(mol.getAtom(6)));
264 assertEquals(1,system.size());
265 assertTrue(system.contains(mol.getAtom(8)));
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"));
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)));
317 mol =
builder.newAtomContainer();
318 IAtom c13 =
new Atom(
"C");
319 c13.setMassNumber(13);
320 mol.addAtom(
new Atom(
"C"));
323 IAtom d2 =
new Atom(
"H");
325 mol2 =
builder.newAtomContainer();
326 mol2.addAtom(
new Atom(
"C"));
341 mol =
builder.newAtomContainer();
342 mol.addAtom(
new Atom(
"Zn"));
343 mol.addAtom(
new Atom(
"C"));
344 mol.addAtom(
new Atom(
"H"));
346 mol2 =
builder.newAtomContainer();
347 mol2.addAtom(
new Atom(
"C"));
348 mol2.addAtom(
new Atom(
"O"));
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"));
387 Set<String> apcRejecting =
new HashSet<String>();
388 apcRejecting.add(
"badAP");
389 apcRejecting.add(
"badO");
419 Set<String[]> apcCombRejecting =
new HashSet<String[]>();
420 apcCombRejecting.add(
new String[] {
"badA",
"Bla"});
421 apcCombRejecting.add(
new String[] {
"foo",
"APCgood:0",
"bar"});
430 mol =
builder.newAtomContainer();
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();
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();
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();
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"));
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);
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);
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");
514 Map<String,String> smarts =
new HashMap<String,String>();
515 smarts.put(
"A",
"C!@-CO");
522 smarts.put(
"B",
"[#6]O");
531 smarts =
new HashMap<String,String>();
532 smarts.put(
"C",
"O-O");
533 smarts.put(
"D",
"CCl");
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"));
General set of constants used in DENOPTIM.
static final String DUMMYATMSYMBOL
Symbol of dummy atom.
static APClass make(String ruleAndSubclass)
Creates an APClass if it does not exist already, or returns the reference to the existing instance.
Class representing a continuously connected portion of chemical object holding attachment points.
void addAP(int atomPositionNumber)
Adds an attachment point with a dummy APClass.
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 setMinFragHeavyAtomCount(int minFragHeavyAtomCount)
void setRejectedFormulaMoreThan(Set< Map< String, Double > > formulaCriteriaMoreThan)
void setFragRetentionSMARTS(Map< String, String > fragRetentionSMARTS)
void setRejectedFormulaLessThan(Map< String, Double > formulaMax)
void setMaxFragHeavyAtomCount(int maxFragHeavyAtomCount)
void setRejectWeirdIsotopes(boolean doRejectWeirdIsotopes)
void setRejectedAPClasses(Set< String > rejectedAPClasses)
void setRejectedElements(Set< String > rejectedElements)
The type of building block.