21import java.awt.BorderLayout;
23import java.awt.Component;
24import java.awt.Cursor;
25import java.awt.Dimension;
26import java.awt.Graphics;
27import java.awt.event.ActionEvent;
28import java.awt.event.ActionListener;
30import java.util.ArrayList;
31import java.util.HashMap;
34import java.util.concurrent.atomic.AtomicInteger;
35import java.util.logging.Logger;
37import javax.swing.BoxLayout;
38import javax.swing.GroupLayout;
39import javax.swing.JButton;
40import javax.swing.JComboBox;
41import javax.swing.JComponent;
42import javax.swing.JLabel;
43import javax.swing.JOptionPane;
44import javax.swing.JPanel;
45import javax.swing.JScrollPane;
46import javax.swing.JSeparator;
47import javax.swing.JSpinner;
48import javax.swing.JSpinner.DefaultEditor;
49import javax.swing.SpinnerNumberModel;
50import javax.swing.SwingConstants;
51import javax.swing.UIManager;
52import javax.swing.event.ChangeEvent;
53import javax.swing.event.ChangeListener;
55import org.openscience.cdk.exception.CDKException;
56import org.openscience.cdk.interfaces.IAtomContainer;
57import org.openscience.cdk.interfaces.IChemObjectBuilder;
58import org.openscience.cdk.io.iterator.IteratingSMILESReader;
59import org.openscience.cdk.layout.StructureDiagramGenerator;
60import org.openscience.cdk.silent.SilentChemObjectBuilder;
62import denoptim.constants.DENOPTIMConstants;
63import denoptim.exception.DENOPTIMException;
64import denoptim.files.FileAndFormat;
65import denoptim.files.FileFormat;
66import denoptim.files.FileUtils;
67import denoptim.files.UndetectedFileFormatException;
68import denoptim.fragmenter.FragmenterTools;
69import denoptim.fragspace.FragmentSpace;
70import denoptim.ga.EAUtils;
71import denoptim.graph.AttachmentPoint;
72import denoptim.graph.DGraph;
73import denoptim.graph.Edge.BondType;
74import denoptim.graph.EmptyVertex;
75import denoptim.graph.GraphPattern;
76import denoptim.graph.SymmetricVertexes;
77import denoptim.graph.Template;
78import denoptim.graph.Template.ContractLevel;
79import denoptim.graph.Vertex;
80import denoptim.graph.Vertex.BBType;
81import denoptim.gui.GraphViewerPanel.LabelType;
82import denoptim.io.DenoptimIO;
83import denoptim.io.IteratingAtomContainerReader;
84import denoptim.molecularmodeling.ThreeDimTreeBuilder;
85import denoptim.programs.fragmenter.FragmenterParameters;
86import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
107 new AtomicInteger(1);
113 new ArrayList<DGraph>();
120 new ArrayList<IAtomContainer>();
130 public static AtomicInteger
graphUID =
new AtomicInteger(1);
154 +
"blocks (BB Space).<br>"
155 +
"Graphs can be inspected without loading any space.<br>"
156 +
"However, loading a space allows to edit and build"
157 +
"graphs manually.</html>";
204 private static final IChemObjectBuilder
builder =
205 SilentChemObjectBuilder.getInstance();
238 super.setLayout(
new BorderLayout());
250 this.setLayout(
new BorderLayout());
264 SwingConstants.VERTICAL));
268 JLabel navigationLabel1 =
new JLabel(
"Graph ");
269 JLabel navigationLabel2 =
new JLabel(
"Number of loaded graphs: ");
274 +
"currently loaded library.");
279 btnAddGraph.setToolTipText(
"Append a graph to the currently loaded "
280 +
"list of graphs.");
281 btnAddGraph.addActionListener(
new ActionListener() {
282 public void actionPerformed(ActionEvent e) {
283 String[] options =
new String[]{
"Build",
"Convert",
"File",
285 int res = JOptionPane.showOptionDialog(
btnAddGraph,
286 "<html>Please choose whether to start creations "
287 +
"of a new graph (Build), <br>"
288 +
"use fragmentation to convert molecules from a "
289 +
"file (Convert), <br>"
290 +
"or import graph from file (File).</html>",
291 "Specify source of new graph",
292 JOptionPane.DEFAULT_OPTION,
293 JOptionPane.QUESTION_MESSAGE,
294 UIManager.getIcon(
"OptionPane.warningIcon"),
303 "<html>No space of building blocks (BB Space) "
304 +
"is currently loaded!<br>"
305 +
"You must load a BB Space to build graphs "
307 +
"contain molecular frgments. <br>"
308 +
"However, without definign a BB Space, "
309 +
"you can still build<br>"
310 +
"graphs made of empty vertexes (i.e., "
311 +
"vertexes contain<br>"
312 +
"no atoms, but only attachment points)."
315 JOptionPane.WARNING_MESSAGE,
316 UIManager.getIcon(
"OptionPane.warningIcon"));
323 e1.printStackTrace();
325 "<html>Could not create graph!<br>"
326 +
"Exception thrown when starting the "
328 +
"of a new graph. Please, report this to "
329 +
"the authors.</html>",
331 JOptionPane.ERROR_MESSAGE,
332 UIManager.getIcon(
"OptionPane.errorIcon"));
341 || inFile.getAbsolutePath().equals(
""))
352 this.getClass().getClassLoader(),
358 String pathnameLastUsedCutRules =
360 if (pathnameLastUsedCutRules !=
null
361 && !pathnameLastUsedCutRules.isBlank())
363 GUIPreferences.lastCutRulesFile =
364 new File(pathnameLastUsedCutRules);
377 || inFile.getAbsolutePath().equals(
""))
388 btnGraphDel.setToolTipText(
"<html>Remove the present graph from the "
389 +
"library.<br><br><b>WARNING:</b> this action cannot be "
391 btnGraphDel.addActionListener(
new ActionListener() {
392 public void actionPerformed(ActionEvent e) {
396 System.out.println(
"Exception while removing the current "
398 e1.printStackTrace();
405 lyoAddDetGraphs.setAutoCreateGaps(
true);
406 lyoAddDetGraphs.setAutoCreateContainerGaps(
true);
407 lyoAddDetGraphs.setHorizontalGroup(lyoAddDetGraphs.createParallelGroup(
408 GroupLayout.Alignment.CENTER)
409 .addGroup(lyoAddDetGraphs.createSequentialGroup()
410 .addComponent(navigationLabel1)
412 .addGroup(lyoAddDetGraphs.createSequentialGroup()
413 .addComponent(navigationLabel2)
415 .addGroup(lyoAddDetGraphs.createSequentialGroup()
418 lyoAddDetGraphs.setVerticalGroup(lyoAddDetGraphs.createSequentialGroup()
419 .addGroup(lyoAddDetGraphs.createParallelGroup(
420 GroupLayout.Alignment.CENTER)
421 .addComponent(navigationLabel1)
423 .addGroup(lyoAddDetGraphs.createParallelGroup()
424 .addComponent(navigationLabel2)
426 .addGroup(lyoAddDetGraphs.createParallelGroup()
435 JLabel mouseModeLab =
new JLabel(
"Mouse mode:");
437 btnPickMode.setToolTipText(
"Makes the mouse select vertex on click.");
438 btnPickMode.addActionListener(
new ActionListener() {
440 public void actionPerformed(ActionEvent e)
446 btnMoveMode.setToolTipText(
"Makes mouse move the graph view.");
447 btnMoveMode.addActionListener(
new ActionListener() {
449 public void actionPerformed(ActionEvent e)
455 GroupLayout lyoMouseModeLayout =
new GroupLayout(
pnlMouseMode);
457 lyoMouseModeLayout.setAutoCreateGaps(
true);
458 lyoMouseModeLayout.setAutoCreateContainerGaps(
true);
459 lyoMouseModeLayout.setHorizontalGroup(lyoMouseModeLayout.createParallelGroup(
460 GroupLayout.Alignment.CENTER)
461 .addComponent(mouseModeLab)
462 .addGroup(lyoMouseModeLayout.createSequentialGroup()
465 lyoMouseModeLayout.setVerticalGroup(lyoMouseModeLayout.createSequentialGroup()
466 .addComponent(mouseModeLab)
467 .addGroup(lyoMouseModeLayout.createParallelGroup()
478 JLabel edtVertxsLab =
new JLabel(
"Edit Graph:");
484 public void actionPerformed(ActionEvent e) {
488 }
catch (Exception e1)
491 "<html>Failed to define a space "
492 +
"of building blocks from the given input.</html>",
494 JOptionPane.ERROR_MESSAGE,
495 UIManager.getIcon(
"OptionPane.errorIcon"));
503 btnAddLibVrtx.setToolTipText(
"<html>Choose a new vertex from the "
504 +
"loaded space of building blocks and<br>"
505 +
"append it to the "
506 +
"attachment point/s selected in the current graph.<html>");
509 public void actionPerformed(ActionEvent e) {
513 "<html>No space of building blocks is currently "
515 +
"You must first load a space in order to add"
516 +
"vertexes from such space.</html>",
518 JOptionPane.ERROR_MESSAGE,
519 UIManager.getIcon(
"OptionPane.errorIcon"));
522 ArrayList<AttachmentPoint> selAps =
524 if (selAps.size() == 0)
527 "<html>No attachment point selected!<br>"
528 +
"Drag the mouse to select APs.<br> "
529 +
"Click again to unselect.</html>",
531 JOptionPane.ERROR_MESSAGE,
532 UIManager.getIcon(
"OptionPane.errorIcon"));
552 btnAddEmptyVrtx.setToolTipText(String.format(
"<html><body width='%1s'>"
553 +
"Creates an empty vertex and appends it "
554 +
"to the attachment points selected in the current graph.<br>"
555 +
"Empty vertices have attachment points but do not contain "
556 +
"atoms. Therefore, they can be used as place holders to define the "
557 +
"graph structure without specifing an actual vertex."
561 public void actionPerformed(ActionEvent e) {
562 ArrayList<AttachmentPoint> selAps =
563 new ArrayList<AttachmentPoint> ();
567 if (selAps.size() == 0)
571 "<html>No attachment point selected!<br>"
572 +
"Drag the mouse to select APs.<br> "
573 +
"Click again to unselect.</html>",
575 JOptionPane.ERROR_MESSAGE,
576 UIManager.getIcon(
"OptionPane.errorIcon"));
585 btnDelSel =
new JButton(
"Remove Vertex");
586 btnDelSel.setToolTipText(
"<html>Removes the selected vertices from "
587 +
"the system.<br><br><b>WARNING:</b> this action cannot be "
590 btnDelSel.addActionListener(
new ActionListener() {
591 public void actionPerformed(ActionEvent e) {
592 ArrayList<Vertex> selVrtx =
594 if (selVrtx.size() == 0)
597 "<html>No vertex selected! Drag the "
598 +
"mouse to select vertices."
599 +
"<br>Click on background to unselect.</html>",
601 JOptionPane.ERROR_MESSAGE,
602 UIManager.getIcon(
"OptionPane.errorIcon"));
644 btnAddChord.setToolTipText(
"<html>Add a ring-closing edge between two "
645 +
"selected vertices.<html>");
647 btnAddChord.addActionListener(
new ActionListener() {
648 public void actionPerformed(ActionEvent e) {
649 ArrayList<Vertex> selVrtxs =
651 if (selVrtxs.size() != 2)
654 "<html>Number of selected vertices: "
655 + selVrtxs.size() +
" <br>"
656 +
"Please, drag the mouse and "
657 +
"select only two vertices!<br> "
658 +
"Click again to unselect.</html>",
660 JOptionPane.ERROR_MESSAGE,
661 UIManager.getIcon(
"OptionPane.errorIcon"));
681 btnAddSymSet.setToolTipText(
"<html>Add a symmetric set that includes "
682 +
"all selected vertexes.<html>");
685 public void actionPerformed(ActionEvent e) {
686 List<Vertex> selVrtxs =
688 if (selVrtxs.size() < 2)
691 "<html>Number of selected vertices: "
692 + selVrtxs.size() +
" <br>"
693 +
"Please, drag the mouse and "
694 +
"select two or more vertices!<br> "
695 +
"Click again to unselect.</html>",
697 JOptionPane.ERROR_MESSAGE,
698 UIManager.getIcon(
"OptionPane.errorIcon"));
708 String.format(
"<html><body width='%1s'>"
709 +
"Could not create SymmetriSet:<br>"
710 + e1.getMessage() +
"</html>", 300),
712 JOptionPane.ERROR_MESSAGE,
713 UIManager.getIcon(
"OptionPane.errorIcon"));
733 lyoEditVertxs.setAutoCreateGaps(
true);
734 lyoEditVertxs.setAutoCreateContainerGaps(
true);
735 lyoEditVertxs.setHorizontalGroup(lyoEditVertxs.createParallelGroup(
736 GroupLayout.Alignment.CENTER)
737 .addComponent(edtVertxsLab)
744 lyoEditVertxs.setVerticalGroup(lyoEditVertxs.createSequentialGroup()
745 .addComponent(edtVertxsLab)
758 JLabel lblShowHideLabels =
new JLabel(
"Show/Hide labels:");
764 btnLabAPC.setToolTipText(
"Show/Hide attachment point class labels.");
770 btnLabBT.setToolTipText(
"Show/Hide bond type labels.");
776 btnLabBB.setToolTipText(
"Show/Hide building block ID labels.");
780 lyoShowAttr.setAutoCreateGaps(
true);
781 lyoShowAttr.setAutoCreateContainerGaps(
true);
782 lyoShowAttr.setHorizontalGroup(lyoShowAttr.createParallelGroup(
783 GroupLayout.Alignment.CENTER)
784 .addComponent(lblShowHideLabels)
788 lyoShowAttr.setVerticalGroup(lyoShowAttr.createSequentialGroup()
789 .addComponent(lblShowHideLabels)
802 btnSaveEdits.setToolTipText(
"<html>Save the current graph replacing"
803 +
" <br>the original one in the currently loaded library.</html>");
805 public void actionPerformed(ActionEvent e) {
815 super.add(commandsPane, BorderLayout.SOUTH);
818 btnOpenGraphs.setToolTipText(
"Reads graphs or structures from file.");
820 public void actionPerformed(ActionEvent e) {
822 if (inFile ==
null || inFile.getAbsolutePath().equals(
""))
831 JButton btnSaveGraphs =
new JButton(
"Export Graphs");
832 btnSaveGraphs.setToolTipText(
"Write all graphs to a file.");
833 btnSaveGraphs.addActionListener(
new ActionListener() {
834 public void actionPerformed(ActionEvent e) {
837 if (fileAndFormat ==
null)
841 File outFile = fileAndFormat.
file;
846 Logger.getLogger(
"GUILogger"),
851 JOptionPane.showMessageDialog(btnSaveGraphs,
852 "Could not write to '" + outFile +
"'!.",
854 JOptionPane.PLAIN_MESSAGE,
855 UIManager.getIcon(
"OptionPane.errorIcon"));
863 commandsPane.
add(btnSaveGraphs);
865 JButton btnSaveVrtxs =
new JButton(
"Export Vertexes");
866 btnSaveVrtxs.setToolTipText(
"Write all graphs to a file.");
867 btnSaveVrtxs.addActionListener(
new ActionListener() {
868 public void actionPerformed(ActionEvent e) {
871 if (fileAndFormat ==
null)
875 File outFile = fileAndFormat.
file;
878 List<Vertex> vertexes =
new ArrayList<Vertex>();
881 vertexes.addAll(graph.getVertexList());
884 fileAndFormat.
format, vertexes,
false);
888 ex.printStackTrace();
889 JOptionPane.showMessageDialog(btnSaveVrtxs,
890 "Could not write to '" + outFile +
"'!",
892 JOptionPane.PLAIN_MESSAGE,
893 UIManager.getIcon(
"OptionPane.errorIcon"));
901 commandsPane.
add(btnSaveVrtxs);
903 JButton btnSaveTmpl =
new JButton(
"Export Templates");
904 btnSaveTmpl.setToolTipText(
"Make templates from the graphs and same "
906 btnSaveTmpl.addActionListener(
new ActionListener() {
907 public void actionPerformed(ActionEvent e) {
911 tmplPropDialog.pack();
918 @SuppressWarnings(
"unchecked")
919 Map<String,List<Object>> configs = (Map<String,List<Object>>) o;
921 ArrayList<Vertex> templates =
922 new ArrayList<Vertex>();
935 if (fileAndFormat ==
null)
939 File outFile = fileAndFormat.
file;
950 ex.printStackTrace();
951 JOptionPane.showMessageDialog(btnSaveTmpl,
952 "Could not write to '" + outFile +
"'! "
953 +
"Hint: "+ex.getMessage(),
955 JOptionPane.ERROR_MESSAGE,
956 UIManager.getIcon(
"OptionPane.errorIcon"));
964 commandsPane.
add(btnSaveTmpl);
966 JButton btnCanc =
new JButton(
"Close Tab");
967 btnCanc.setToolTipText(
"Closes this graph handler.");
969 commandsPane.
add(btnCanc);
971 JButton btnHelp =
new JButton(
"?");
972 btnHelp.setToolTipText(
"<html>Hover over the buttons and fields "
973 +
"to get a tip.</html>");
974 btnHelp.addActionListener(
new ActionListener() {
975 public void actionPerformed(ActionEvent e) {
976 String txt =
"<html><body width='%1s'>"
977 +
"<p>This tab allows to create, inspect, and edit "
978 +
"the graphs that DENOPTIM used to define candidate "
979 +
"items, such as molecules.</p>"
981 +
"<p>In general, you can hover over any button or"
982 +
"viewer to get a tip on its usage.</p>"
984 +
"<p>DENOPTIMGraphs is drawn in the "
985 +
"central panel (i.e., the graph viewer). "
986 +
"Each vertex is shown as a rounded square, and each "
987 +
"edge as an arrow (or a line, for undirected edges)."
988 +
" The color of a node represent the type of building"
990 +
"<li>red for the scaffold,</li>"
991 +
"<li>orange for ring-closing vertices,</li>"
992 +
"<li>green for capping groups,</li>"
993 +
"<li>blue for standard fragments,</li>"
994 +
"<li>yellow for attachment points.</li>"
996 +
"<p>If the loaded DENOPTIMGraph is associated with "
997 +
"a chemical structure, the latter is shown in the "
998 +
"molecular viewer (bottom-left panel).</p>"
999 +
"<p>The content of a vertex in the graph viewer, "
1000 +
"i.e., a molecular fragment or an embedded graph, "
1001 +
"can be shown in the vertex viewer (top-left panel) "
1002 +
"upon selecting (see below) that vertex in the graph "
1004 +
"<p>A space of building blocks must be loaded to "
1005 +
"enable inspection of graph vertexes that depend on"
1006 +
"a building block space.</p>"
1008 +
"<p><b>Control the graph view</b></p>"
1010 +
"<li>Use mouse mode <i>Pick</i> to enable selection "
1011 +
"of vertexes by single left click.</li>"
1012 +
"<li>Use mouse mode <i>Move</i> to drag the graph in "
1013 +
"any direction, <code>ALT</code>+drag to rotate, and "
1014 +
"<code>CTRL</code>+drag to skew the graph. Wheel, or "
1015 +
"analogous, to zoom in/out.</li>"
1016 +
"</ul>Mouse mode can be changed also by double click "
1017 +
"in the graph area, away from any vertex/edge, and "
1018 +
"hitting <code>p</code> for <i>Pick</i> or "
1019 +
"<code>t</code> for <i>Move</i> "
1020 +
"(or <i>Transform</i>).</p>"
1021 +
"<p>Right-click in the graph viewer shows a menu "
1022 +
"with shortcuts to refine node location, or "
1023 +
"show/hide graph labels.</p>"
1025 +
"<p><b>Control the fragment and molecular views</b>"
1027 +
"<p>Right-click on the Jmol viewer will open the "
1028 +
"Jmol menu. However, any change on the molecular "
1029 +
"object will not be saved.</p></html>";
1030 JOptionPane.showMessageDialog(btnHelp,
1031 String.format(txt, 500),
1033 JOptionPane.PLAIN_MESSAGE);
1036 commandsPane.
add(btnHelp);
1065 JOptionPane.showMessageDialog(
parent,
1066 "<html>No elements selected! Drag the "
1067 +
"mouse to select elements."
1068 +
"<br>Click on background to unselect.</html>",
1070 JOptionPane.ERROR_MESSAGE,
1071 UIManager.getIcon(
"OptionPane.errorIcon"));
1093 ArrayList<AttachmentPoint> selAps)
1097 makeEmptyVertexDialog.pack();
1098 Object evObj = makeEmptyVertexDialog.
showDialog();
1104 ArrayList<Vertex> lst =
new ArrayList<Vertex>(1);
1107 fragSelector.
ctrlPane.setVisible(
false);
1108 if (selAps.size() == 0)
1110 fragSelector.
btnDone.setText(
"Confirm");
1113 fragSelector.
btnDone.setText(
"Confirm Selected AP");
1116 fragSelector.
load(lst, 0);
1118 if (selected ==
null)
1123 @SuppressWarnings(
"unchecked")
1124 ArrayList<Integer> trgFragApId =
1125 ((ArrayList<ArrayList<Integer>>)selected).get(0);
1126 int incomingAPId = trgFragApId.get(1);
1128 if (selAps.size() == 0)
1137 e1.printStackTrace();
1138 JOptionPane.showMessageDialog(
this,
"Could not make the "
1139 +
"new graph. " + e1.getMessage(),
1141 JOptionPane.PLAIN_MESSAGE,
1142 UIManager.getIcon(
"OptionPane.errorIcon"));
1172 String msg =
"<html><body width='%1s'>"
1173 +
"Please choose the type of building block to use as first "
1174 +
"vertex of the graph.";
1175 String[] options =
null;
1176 String defaultOpt =
null;
1179 options =
new String[]{
"Scaffold",
"Fragment",
"EmptyVertex",
1181 defaultOpt = options[3];
1182 msg = msg +
"Use a scaffold if the graph is meant to "
1183 +
"represent a necessary portion of a candidate entity.</html>";
1185 options =
new String[]{
"EmptyVertex",
"Cancel"};
1186 defaultOpt = options[1];
1188 int res = JOptionPane.showOptionDialog(
this,String.format(msg,350),
1189 "Specify type of initial building block",
1190 JOptionPane.DEFAULT_OPTION,
1191 JOptionPane.QUESTION_MESSAGE,
1192 UIManager.getIcon(
"OptionPane.warningIcon"),
1200 ArrayList<Vertex> vrtxLib =
new ArrayList<Vertex>();
1207 vrtxLib.add(bb.clone());
1215 vrtxLib.add(bb.clone());
1225 ArrayList<AttachmentPoint> selectedAPs =
new ArrayList<>();
1233 if (vrtxLib.size() == 0)
1235 JOptionPane.showMessageDialog(
this,
"No building blocks of the "
1238 JOptionPane.PLAIN_MESSAGE,
1239 UIManager.getIcon(
"OptionPane.errorIcon"));
1246 fragSelector.
load(vrtxLib, 0);
1248 if (selected ==
null)
1253 @SuppressWarnings(
"unchecked")
1254 ArrayList<Integer> trgFragApId = ((ArrayList<ArrayList<Integer>>)selected)
1256 int scaffFragId = trgFragApId.get(0);
1264 Vertex firstVertex =
null;
1268 firstBBId, scaffFragId, rootType,
fragSpace);
1271 JOptionPane.showMessageDialog(
this,
"Could not retrieve the "
1272 +
"requested building blocks. " + e.getMessage(),
1274 JOptionPane.PLAIN_MESSAGE,
1275 UIManager.getIcon(
"OptionPane.errorIcon"));
1313 if (rcvs.size() != 2)
1315 JOptionPane.showMessageDialog(
this,
1316 "<html>Number of selected vertices: "
1317 + rcvs.size() +
" <br>"
1318 +
"Please, drag the mouse and "
1319 +
"select only two vertices!<br> "
1320 +
"Click again to unselect.</html>",
1322 JOptionPane.ERROR_MESSAGE,
1323 UIManager.getIcon(
"OptionPane.errorIcon"));
1346 ArrayList<AttachmentPoint> selAps)
1349 if (selAps.size() == 0)
1351 JOptionPane.showMessageDialog(
this,
"No AP selected in the "
1354 JOptionPane.PLAIN_MESSAGE,
1355 UIManager.getIcon(
"OptionPane.errorIcon"));
1362 ArrayList<Vertex> vertxLib =
new ArrayList<Vertex>();
1363 String[] options =
new String[]{
"Any Vertex",
1366 int res = JOptionPane.showOptionDialog(
this,
1367 "<html>Choose a subset of possible vertices:</html>",
1368 "Choose Vertex Subset",
1369 JOptionPane.DEFAULT_OPTION,
1370 JOptionPane.QUESTION_MESSAGE,
1371 UIManager.getIcon(
"OptionPane.warningIcon"),
1378 vertxLib =
new ArrayList<Vertex>();
1381 vertxLib.add(bb.clone());
1390 vertxLib =
new ArrayList<Vertex>();
1393 vertxLib.add(bb.clone());
1400 if (vertxLib.size() == 0)
1402 JOptionPane.showMessageDialog(
this,
"No vertexes in the library",
1404 JOptionPane.PLAIN_MESSAGE,
1405 UIManager.getIcon(
"OptionPane.errorIcon"));
1413 fragSelector.
load(vertxLib, 0);
1415 if (selected ==
null)
1419 @SuppressWarnings(
"unchecked")
1420 ArrayList<Integer> trgFragApId =
1421 ((ArrayList<ArrayList<Integer>>)selected).get(0);
1422 Vertex chosenVrtx = vertxLib.get(trgFragApId.get(0));
1430 ArrayList<AttachmentPoint> selAps)
1433 if (chosenVrtx ==
null)
1438 for (
int i=0; i<selAps.size(); i++)
1448 JOptionPane.showMessageDialog(
this,
"Unable to make new edge. "
1451 JOptionPane.PLAIN_MESSAGE,
1452 UIManager.getIcon(
"OptionPane.errorIcon"));
1461 ArrayList<AttachmentPoint> srcAPs)
1472 ArrayList<AttachmentPoint> compatAps =
1483 int vId = ap.getOwner().hashCode();
1484 int apId = ap.getOwner().getIndexOfAP(ap);
1488 String prop = vrtx.
getProperty(PRESELPROP).toString();
1489 vrtx.
setProperty(PRESELPROP,prop+PRESELPROPSEP+apId);
1520 Logger.getLogger(
"GUILogger"),
GUI.
PRNG);
1538 }
catch (Throwable e) {
1539 System.out.println(
"Could not read graphs from " + file);
1544 mainPanel.setCursor(Cursor.getPredefinedCursor(
1545 Cursor.DEFAULT_CURSOR));
1561 List<IAtomContainer> mols =
new ArrayList<IAtomContainer>();
1562 boolean make2D =
false;
1563 StructureDiagramGenerator sdg =
null;
1569 IteratingSMILESReader.class))
1574 sdg =
new StructureDiagramGenerator();
1576 }
catch (Exception e1)
1578 String msg =
"<html><body width='%1s'>Could not read molecules "
1579 +
"from '" + file.getAbsolutePath() +
"' and convert them "
1580 +
"to graphs.</html>";
1581 JOptionPane.showMessageDialog(parent, String.format(msg,400),
1583 JOptionPane.ERROR_MESSAGE,
1584 UIManager.getIcon(
"OptionPane.errorIcon"));
1595 List<DGraph> graphs =
new ArrayList<DGraph>();
1597 while (iterMolsToFragment.
hasNext())
1600 IAtomContainer mol = iterMolsToFragment.
next();
1606 sdg.generateCoordinates(mol);
1607 }
catch (CDKException e)
1610 e.printStackTrace();
1622 String msg =
"<html><body width='%1s'>Unable to convert "
1623 +
"molecule " + i +
" (" + mol.getAtomCount()
1624 +
" atoms) to DENOPTIM graph. " + de.getMessage()
1626 JOptionPane.showMessageDialog(parent, String.format(msg,400),
1628 JOptionPane.WARNING_MESSAGE,
1629 UIManager.getIcon(
"OptionPane.warningIcon"));
1641 String msg =
"<html><body width='%1s'>Unable to embed "
1642 +
"ring systems of molecule " + i
1643 +
" (" + mol.getAtomCount()
1644 +
" atoms) into Templates. Returning graph without "
1645 +
"embedding of rings. " + e.getMessage()
1647 JOptionPane.showMessageDialog(parent, String.format(msg,400),
1649 JOptionPane.WARNING_MESSAGE,
1650 UIManager.getIcon(
"OptionPane.warningIcon"));
1659 if (graphs.size() < 1)
1661 JOptionPane.showMessageDialog(parent,
1662 "<html>Conversion produced no graphs!</html>",
1664 JOptionPane.WARNING_MESSAGE,
1665 UIManager.getIcon(
"OptionPane.warningIcon"));
1671 if (graphs.size() > 0)
1692 ArrayList<IAtomContainer> mols =
new ArrayList<IAtomContainer>();
1697 }
catch (Exception e1)
1706 file.getAbsolutePath()));
1708 System.err.println(
"WARNING: Could not read molecular "
1709 +
"representation from " + file);
1710 for (
int i=0; i<graphs.size(); i++)
1719 for (
int i=0; i<graphs.size(); i++)
1727 if (graphs.size() > 0)
1744 ArrayList<DGraph> graphs =
new ArrayList<DGraph>();
1753 String[] options = {
"Abandon",
"SDF",
"JSON"};
1754 int res = JOptionPane.showOptionDialog(
this,
1755 "<html>Failed to detect file type from file's "
1757 +
"Please, tell me how to interpret file <br>"
1758 +
"'" + file.getAbsolutePath() +
"'<br>"
1759 +
"or 'Abandon' to give up.</html>",
1760 "Specify File Type",
1761 JOptionPane.DEFAULT_OPTION,
1762 JOptionPane.QUESTION_MESSAGE,
1763 UIManager.getIcon(
"OptionPane.warningIcon"),
1769 graphs =
new ArrayList<DGraph>();
1774 file.getAbsolutePath());
1779 file.getAbsolutePath());
1786 e.printStackTrace();
1787 String msg =
"<html><body width='%1s'>Could not read graph from "
1789 +
"'" + file.getAbsolutePath()
1790 +
"'<br>Hint on cause: ";
1791 msg = msg + e.getClass().getName()+
" (";
1792 if (e.getCause() !=
null)
1794 msg = msg + e.getCause();
1796 if (e.getMessage() !=
null)
1798 msg = msg +
" " + e.getMessage();
1801 msg = msg +
"</html>";
1802 JOptionPane.showMessageDialog(
this,String.format(msg,400),
1804 JOptionPane.PLAIN_MESSAGE,
1805 UIManager.getIcon(
"OptionPane.errorIcon"));
1819 JOptionPane.showMessageDialog(
this,
1820 "No list of graphs loaded.",
1822 JOptionPane.PLAIN_MESSAGE,
1823 UIManager.getIcon(
"OptionPane.errorIcon"));
1883 this.inEnabled = var;
1907 fsDefinitionDialog.pack();
1908 fsDefinitionDialog.setVisible(
true);
1931 .getTextField().setEditable(
true);
1933 .getTextField().setForeground(Color.BLACK);
1949 .getTextField().setEditable(
false);
1951 .getTextField().setForeground(Color.GRAY);
2063 @SuppressWarnings(
"serial")
2080 super(refForPlacement);
2081 setTitle(
"Define Properties of Templates");
2082 centralPanel =
new JPanel();
2083 centralPanel.setLayout(
new BoxLayout(
2084 centralPanel, SwingConstants.VERTICAL));
2086 listPanel =
new JPanel();
2087 listPanel.setLayout(
new BoxLayout(listPanel, SwingConstants.VERTICAL));
2088 scrollPanel =
new JScrollPane(listPanel);
2089 for (
int i=0; i<num; i++)
2091 centralPanel.add(scrollPanel);
2093 this.btnDone.setText(
"OK");
2094 this.btnDone.setToolTipText(
"Confirm properties.");
2095 this.btnDone.addActionListener(
new ActionListener() {
2098 public void actionPerformed(ActionEvent e) {
2100 Map<String,List<Object>> selection =
2101 new HashMap<String,List<Object>>();
2103 selection.put(
BBTYPEKEY,
new ArrayList<>());
2104 for (Component c : listPanel.getComponents())
2121 this.btnCanc.setEnabled(
true);
2122 this.btnCanc.setVisible(
true);
2123 this.btnCanc.setToolTipText(
"Abandon");
2125 super.addToCentralPane(centralPanel);
2136 JComboBox<ContractLevel> contractCmb =
new JComboBox<ContractLevel>(
2139 private String contractTolTip =
"<html><body width='%1s'>"
2140 +
"Speicfy the type of contract of the template, i.e., "
2142 +
"extent the graph embedded in the template can change in "
2143 +
"structure and/or identity of the vertexes.</html>";
2145 JComboBox<BBType> bbTypeCmb =
new JComboBox<BBType>(
BBType.values());
2147 private String bbtTolTip =
"<html><body width='%1s'>"
2148 +
"Speicfy the type of building block of the vertex. This"
2149 +
"determines, for instance, the type of other vertexes "
2150 +
"that can be used to replace thi one (if such mutation "
2151 +
"is permitted).</html>";
2153 private int szTolTip = 250;
2163 this.add(
new JLabel(
"#" + (
id+1)));
2165 JLabel contractLbl =
new JLabel(
" Contract:");
2166 contractLbl.setToolTipText(String.format(contractTolTip,
2168 this.add(contractLbl);
2169 contractCmb.setToolTipText(String.format(contractTolTip,
2171 this.add(contractCmb);
2173 JLabel bbtLbl =
new JLabel(
" Building Block Type:");
2174 bbtLbl.setToolTipText(String.format(bbtTolTip,szTolTip));
2176 bbTypeCmb.setToolTipText(String.format(bbtTolTip,szTolTip));
2178 this.add(bbTypeCmb);
General set of constants used in DENOPTIM.
static final String PROVENANCE
SDF tag containing provenance data for a graph.
static FileFormat detectFileFormat(File inFile)
Inspects a file/folder and tries to detect if there is one of the data sources that is recognized by ...
static void addToRecentFiles(String fileName, FileFormat ff)
Appends an entry to the list of recent files.
Class defining a space of building blocks.
ArrayList< AttachmentPoint > getAPsCompatibleWithThese(ArrayList< AttachmentPoint > srcAPs)
Searches for all attachment points that are compatible with the given list of attachment points.
ArrayList< Vertex > getCappingLibrary()
ArrayList< Vertex > getScaffoldLibrary()
ArrayList< Vertex > getFragmentLibrary()
Helper methods for the genetic algorithm.
static DGraph makeGraphFromFragmentationOfMol(IAtomContainer mol, List< CuttingRule > cuttingRules, Logger logger, ScaffoldingPolicy scaffoldingPolicy)
Converts a molecule into a DGraph by fragmentation and re-assembling of the fragments.
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
Container for the list of vertices and the edges that connect them.
void addVertex(Vertex vertex)
Appends a vertex to this graph without creating any edge.
DGraph embedPatternsInTemplates(GraphPattern pattern, FragmentSpace fragSpace)
Searches for the given pattern type and generated a new graph where each set of (clones of) vertexes ...
void removeVertex(Vertex vertex)
Remove a vertex from this graph.
void appendVertexOnAP(AttachmentPoint srcAP, AttachmentPoint trgAP)
Append a vertex to this graph: adds the new vertex to the list of vertices belonging to the graph,...
void addSymmetricSetOfVertices(SymmetricVertexes symSet)
Adds a symmetric set of vertices to this graph.
An empty vertex has the behaviors of a vertex, but has no molecular structure.
A collection of Vertexs that are related by a relation that we call "symmetry", even though this clas...
void setInnerGraph(DGraph innerGraph)
void setContractLevel(ContractLevel contract)
Imposes the given contract to this template.
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
abstract Vertex clone()
Returns a deep-copy of this vertex.
void setVertexId(long vertexId2)
Object getProperty(Object property)
void setProperty(Object key, Object property)
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
static Vertex newVertexFromLibrary(int bbId, Vertex.BBType bbt, FragmentSpace fragSpace)
Builds a new molecular fragment kind of vertex.
A modal dialog to define a fragment space and load it.
FragmentSpace makeFragSpace()
Reads all the parameters, calls the interpreters, and eventually creates the static FragmentSpace obj...
Remove the card from the deck of cards and takes care of removing also the entry in the list of activ...
Class of GUI panels meant to occupy one card in the deck-of-cards layout of the main panel.
GUIMainPanel mainPanel
The main panel (cards deck)
File opener for DENOPTIM GUI.
static File pickFileWithGraph(Component parent)
static File pickFile(Component parent)
GUI component to provide pathname where to save stuff.
static FileAndFormat pickFileForSavingVertexes(Component parent)
static FileAndFormat pickFileForSavingGraphs(Component parent)
Utility class for a form to configure a template via the GUI.
TemplateConfiguration(int id)
Constructor.
JComboBox< BBType > bbTypeCmb
JComboBox< ContractLevel > contractCmb
Dialog to configure one or more templates.
ConfigTemplateDialog(Component refForPlacement, int num)
Creates a modal dialog with a specified number of limes allowing to configure the properties of the t...
void setEnabled(boolean var)
Enables/disable the listener.
void stateChanged(ChangeEvent event)
GraphSpinnerChangeEvent()
Map< LabelType, Boolean > lastIteration
showHideLabelsListener(JComponent parent, LabelType labTyp)
void actionPerformed(ActionEvent e)
A panel that understands DENOPTIM graphs and allows to create and edit them.
void protectEditedSystem()
void removeCurrentDnGraph()
JSpinner graphNavigSpinner
void initializeCurrentGraph()
FragmentSpace fragSpace
The fragment space this handler works with.
void appendGraphsFromConvertingMolecule(File file, FragmenterParameters frgParams, Component parent)
ArrayList< DGraph > readGraphsFromFile(File file)
static AtomicInteger graphHandlerTabUID
Unique identified for instances of this handler.
final GraphSpinnerChangeEvent graphSpinnerListener
void extendGraphFromFragSpace(ArrayList< AttachmentPoint > selAps)
Extends the current graph by appending a node to a specific free AP on the growing graph.
DGraph dnGraph
The unsaved version of the currently loaded graph.
ArrayList< DGraph > dnGraphLibrary
The currently loaded list of graphs.
static final long serialVersionUID
Version UID.
GraphVertexMolViewerPanel visualPanel
static AtomicInteger graphUID
Unique identified for graphs built here.
void importGraphsFromFile(File file)
Imports graphs from file.
void startGraphFromFragSpaceOrCreationOfEmptyVertex()
Start the construction of a new graph from scratch.
void addChordOnGraph(ArrayList< Vertex > rcvs)
Edits the currently loaded graph by adding a chord involving the two selected vertices.
Map< Integer, Integer > genToLocIDMap
Map converting fragIDs in fragment library to fragIDs in subset of compatible fragments.
static final IChemObjectBuilder builder
boolean unsavedChanges
Flag signaling that loaded data has changes since last save.
void appendGraphsFromFile(File file)
void collectFragAndAPsCompatibleWithSelectedAPs(ArrayList< AttachmentPoint > srcAPs)
void clearCurrentSystem()
Clears the current graph viewer but keeps track of the latest graph loaded.
GUIGraphHandler(GUIMainPanel mainPanel)
Constructor.
boolean hasUnsavedChanges()
Check whether there are unsaved changes.
void saveUnsavedChanges()
void extendCurrentGraph(AttachmentPoint apOnIncomingVrtx, ArrayList< AttachmentPoint > selAps)
void loadCurrentGraphIdxToViewer(boolean keepSprites)
Loads the graph corresponding to the field currGrphIdx.
void enableGraphDependentButtons(boolean enable)
void updateGraphListSpinner()
void deprotectEditedSystem()
ArrayList< IAtomContainer > molLibrary
The currently loaded list of molecular representations of the graphs.
void initialize()
Initialize the panel and add buttons.
void createEmptyVertexAndPlaceItInGraph(ArrayList< AttachmentPoint > selAps)
ArrayList< Vertex > compatVrtxs
Subset of vertices for compatible building block selecting GUI.
int currGrphIdx
The index of the currently loaded dnGraph [0–(n-1)}.
Graphical User Interface of the DENOPTIM package.
static final Randomizer PRNG
Random number generator specific for the GUI, and any of its tasks.
The main panel is a deck of cards that occupies all the GUI frame.
JButton btnDone
The button that is used to launch the processing of the data given to the open dialog,...
Object showDialog()
Shows the dialog and restrains the modality to it, until the dialog gets closed.
A panel with a viewer capable of visualising DENOPTIM fragments and allows to create and edit fragmen...
static boolean dialogToDefineCuttingRules(FragmenterParameters settings, ClassLoader classLoader, Component parent, boolean setMolToGraphSettings)
Starts a dialog to define the on-the-fly fragmentation settings.
A modal dialog with a viewer that understands the different types of DENOPTIM vertex and allows to se...
void load(List< Vertex > fragments, int initialId)
Load the list of vertexes to choose from.
void setRequireApSelection(boolean enforced)
Allows to control whether confirming the selection of a vertex without having selected an attachment ...
static final String PRESELECTEDAPSFIELD
Property used to pre-select APs.
static final String PRESELECTEDAPSFIELDSEP
Separator in property used to pre-select APs.
A panel that collects three viewers:
ArrayList< AttachmentPoint > getAPsSelectedInViewer()
Identifies which attachment points are selected in the graph viewer.
void clearMolecularViewer()
Clears the molecular viewer and hides it behind the empty card.
void setMouseMode(ModalGraphMouse.Mode mode)
Alters the functionality of mouse in the graph visualization panel.
final String EMPTYCARDNAME
ArrayList< Vertex > getSelectedNodesInViewer()
Identifies which vertices are selected in the graph viewer.
void bringCardToTopOfMolViewer(String cardName)
Allows to show the given card in the molecular structure viewer.
void moveDividerLocation()
Moved the divider to the location configured by some content-based reasoning.
void clearCurrentSystem()
Clears the current graph viewer but keeps track of the latest graph loaded.
void renderMolVieverToNeedUpdate()
Triggers the generation of the molecular representation of the loaded graph.
boolean hasSelectedNodes()
void resetFragViewerCardDeck()
Changes the appearance of the vertex visualisation panel to an empty card that is consistent with the...
void loadDnGraphToViewer(DGraph dnGraph, IAtomContainer mol, boolean keepSprites)
Loads the given graph into the graph viewer.
void alterLabels(LabelType labelName, boolean show)
Adds/Removes labels to the graph components that are presently selected.
IAtomContainer updateMolevularViewer()
Updates the molecular representation of the loaded graph.
Utility methods for input/output.
static File writeVertexesToFile(File file, FileFormat format, List< Vertex > vertexes)
Writes vertexes to file.
static ArrayList< IAtomContainer > readSDFFile(String fileName)
Reads a file containing multiple molecules (multiple SD format))
static ArrayList< DGraph > readDENOPTIMGraphsFromJSONFile(String fileName)
Reads a list of DGraphs from a JSON file.
static File writeGraphsToFile(File file, FileFormat format, List< DGraph > modGraphs, Logger logger, Randomizer randomizer)
Writes the graphs to file.
static ArrayList< DGraph > readDENOPTIMGraphsFromFile(File inFile)
Reads a list of DGraphs from file.
static ArrayList< DGraph > readDENOPTIMGraphsFromSDFile(String fileName)
Reads a list of <DGraphs from a SDF file.
An iterator that take IAtomContainers from a file, possibly using an available iterating reader,...
Class<?> getIteratorType()
Tool to build build three-dimensional (3D) tree-like molecular structures from DGraph.
IAtomContainer convertGraphTo3DAtomContainer(DGraph graph)
Created a three-dimensional molecular representation from a given DGraph.
Logger getLogger()
Get the name of the program specific logger.
Parameters controlling execution of the fragmenter.
double getLinearAngleLimit()
String getCuttingRulesFilePathname()
void setAddExplicitH(boolean addExplicitH)
Give true to add explicit H atoms on all atoms.
ScaffoldingPolicy getScaffoldingPolicy()
List< CuttingRule > getCuttingRules()
ContractLevel getEmbeddedRingsContract()
boolean embedRingsInTemplate
Flag that enables the embedding of rings in templates upon conversion of molecules into DGraph.
void setWorkingIn3D(boolean workingIn3D)
Sets boolean variable workingIn3D.
Possible chemical bond types an edge can represent.
Enum specifying to what extent the template's inner graph can be changed.
The type of building block.