21import java.awt.BorderLayout;
23import java.awt.Component;
24import java.awt.Cursor;
25import java.awt.Dimension;
26import java.awt.event.ActionEvent;
27import java.awt.event.ActionListener;
28import java.beans.PropertyChangeEvent;
29import java.beans.PropertyChangeListener;
30import java.io.BufferedReader;
32import java.io.InputStreamReader;
33import java.util.ArrayList;
36import java.util.concurrent.atomic.AtomicInteger;
38import javax.swing.BoxLayout;
39import javax.swing.DefaultListModel;
40import javax.swing.GroupLayout;
41import javax.swing.JButton;
42import javax.swing.JComponent;
43import javax.swing.JLabel;
44import javax.swing.JList;
45import javax.swing.JOptionPane;
46import javax.swing.JPanel;
47import javax.swing.JScrollPane;
48import javax.swing.JSeparator;
49import javax.swing.JSpinner;
50import javax.swing.JSpinner.DefaultEditor;
51import javax.swing.ListSelectionModel;
52import javax.swing.SpinnerNumberModel;
53import javax.swing.SwingConstants;
54import javax.swing.UIManager;
55import javax.swing.event.ChangeEvent;
56import javax.swing.event.ChangeListener;
57import javax.swing.table.DefaultTableModel;
58import javax.vecmath.Point3d;
60import org.openscience.cdk.interfaces.IAtom;
61import org.openscience.cdk.interfaces.IAtomContainer;
62import org.openscience.cdk.interfaces.IBond;
64import denoptim.constants.DENOPTIMConstants;
65import denoptim.exception.DENOPTIMException;
66import denoptim.files.FileAndFormat;
67import denoptim.files.FileUtils;
68import denoptim.fragmenter.FragmenterTools;
69import denoptim.graph.APClass;
70import denoptim.graph.AttachmentPoint;
71import denoptim.graph.DGraph;
72import denoptim.graph.Edge.BondType;
73import denoptim.graph.EmptyVertex;
74import denoptim.graph.Fragment;
75import denoptim.graph.Vertex;
76import denoptim.graph.Vertex.BBType;
77import denoptim.io.DenoptimIO;
78import denoptim.programs.fragmenter.CuttingRule;
79import denoptim.programs.fragmenter.FragmenterParameters;
80import denoptim.utils.DummyAtomHandler;
81import denoptim.utils.MoleculeUtils;
171 super.setLayout(
new BorderLayout());
183 this.setLayout(
new BorderLayout());
194 new PropertyChangeListener() {
196 public void propertyChange(PropertyChangeEvent evt) {
214 JLabel navigationLabel1 =
new JLabel(
"Vertex # ");
215 JLabel navigationLabel2 =
new JLabel(
"Current library size: ");
218 navigSpinner =
new JSpinner(
new SpinnerNumberModel(0, 0, 0, 1));
219 navigSpinner.setToolTipText(
"Move to vertex number # in the currently loaded library.");
231 btnAddVrtx.setToolTipText(
"Append vertices taken from a file.");
232 btnAddVrtx.addActionListener(
new ActionListener() {
233 public void actionPerformed(ActionEvent e) {
235 if (inFile ==
null || inFile.getAbsolutePath().equals(
""))
240 ArrayList<Vertex> vrtxLib =
new ArrayList<>();
243 }
catch (Exception e1) {
244 e1.printStackTrace();
246 "<html>Could not read building blocks from file"
247 +
"<br>'" + inFile +
"'"
248 +
"<br>Hint on cause: " + e1.getMessage()
251 JOptionPane.ERROR_MESSAGE,
252 UIManager.getIcon(
"OptionPane.errorIcon"));
256 if (vrtxLib.size() == 0)
259 "<html>No building blocks in file"
260 +
"<br>'" + inFile +
"'</html>",
262 JOptionPane.ERROR_MESSAGE,
263 UIManager.getIcon(
"OptionPane.errorIcon"));
267 if (vrtxLib.size() == 1)
273 String[] options =
new String[]{
"All",
276 String txt =
"<html><body width='%1s'>Do you want to "
277 +
"append all building blocks or only selected ones?"
279 int res = JOptionPane.showOptionDialog(
btnAddVrtx,
280 String.format(txt,200),
281 "Append Building Blocks",
282 JOptionPane.DEFAULT_OPTION,
283 JOptionPane.QUESTION_MESSAGE,
284 UIManager.getIcon(
"OptionPane.warningIcon"),
300 ArrayList<Vertex> selectedVrtxs =
301 new ArrayList<Vertex>();
305 vrtxSelector.
load(vrtxLib, 0);
308 if (selected !=
null)
310 @SuppressWarnings(
"unchecked")
311 ArrayList<ArrayList<Integer>> selList =
312 (ArrayList<ArrayList<Integer>>) selected;
313 for (ArrayList<Integer> pair : selList)
315 selectedVrtxs.add(vrtxLib.get(pair.get(0)));
327 btnDelVrtx.setToolTipText(
"Remove the present building block from the "
329 btnDelVrtx.addActionListener(
new ActionListener() {
330 public void actionPerformed(ActionEvent e) {
334 System.out.println(
"Exception while removing the current "
335 +
"building block:");
336 e1.printStackTrace();
348 JLabel lblImportStruct =
new JLabel(
"Import a structure from");
350 btnOpenMol.setToolTipText(
"Imports a chemical system"
352 btnOpenMol.addActionListener(
new ActionListener() {
353 public void actionPerformed(ActionEvent e) {
355 if (inFile ==
null || inFile.getAbsolutePath().equals(
""))
366 +
" from SMILES string.<br>The conversion of SMILES "
367 +
"to 3D structure requires"
368 +
"<br> an internet connection.</html>");
370 public void actionPerformed(ActionEvent e) {
372 "Please input SMILES: ");
373 if (smiles !=
null && !smiles.trim().equals(
""))
381 lyoImportStructure.setAutoCreateGaps(
true);
382 lyoImportStructure.setAutoCreateContainerGaps(
true);
383 lyoImportStructure.setHorizontalGroup(lyoImportStructure.createParallelGroup(
384 GroupLayout.Alignment.CENTER)
385 .addComponent(lblImportStruct)
386 .addGroup(lyoImportStructure.createSequentialGroup()
389 lyoImportStructure.setVerticalGroup(lyoImportStructure.createSequentialGroup()
390 .addComponent(lblImportStruct)
391 .addGroup(lyoImportStructure.createParallelGroup()
400 btnEmptFrag.setToolTipText(
"<html>Creates an empty vertex:<br>a vertex "
401 +
"that contains no molecular structure.<html>");
402 btnEmptFrag.addActionListener(
new ActionListener() {
403 public void actionPerformed(ActionEvent e) {
406 makeEmptyVertexDialog.pack();
407 Object ev = makeEmptyVertexDialog.
showDialog();
412 ArrayList<Vertex> lst =
new ArrayList<Vertex>(1);
416 fragSelector.
load(lst, 0);
417 fragSelector.
btnDone.setText(
"Confirm");
418 fragSelector.
ctrlPane.setVisible(
false);
421 if (selected ==
null)
435 btnAtmToAP.setToolTipText(
"<html>Replaces the selected atoms with "
436 +
"attachment points.<br>Click on atoms to select"
437 +
" them. Click again to unselect.<br>"
438 +
"<br><b>WARNING:</b> this action cannot be undone!<html>");
439 btnAtmToAP.addActionListener(
new ActionListener() {
440 public void actionPerformed(ActionEvent e) {
443 ArrayList<IAtom> selectedAtms =
446 if (selectedAtms.size() == 0)
449 "<html>No atom selected! Click on atoms to select"
450 +
" them.<br>Click again to unselect.</html>",
452 JOptionPane.ERROR_MESSAGE,
453 UIManager.getIcon(
"OptionPane.errorIcon"));
467 if (selectedAPCs.size() == 0)
472 String apClass = selectedAPCs.get(0).toString();
474 ArrayList<IAtom> failed =
new ArrayList<IAtom>();
475 for (IAtom atm : selectedAtms)
482 for (IAtom atm : failed)
484 selectedAtms.remove(atm);
486 if (selectedAtms.size() == 0)
504 btnChop =
new JButton(
"Chop Structure");
505 btnChop.setToolTipText(String.format(
"<html><body width='%1s'>"
506 +
"Applies cutting rules on "
507 +
"the current structure to generate fragments.</html>", 400));
508 btnChop.addActionListener(
new ActionListener() {
509 public void actionPerformed(ActionEvent event) {
514 JOptionPane.showMessageDialog(
btnChop,
515 "<html>System contains 0 bonds. "
516 +
"Nothing to chop.</html>",
518 JOptionPane.ERROR_MESSAGE,
519 UIManager.getIcon(
"OptionPane.errorIcon"));
526 this.getClass().getClassLoader(),
532 String pathnameLastUsedCutRules =
534 if (pathnameLastUsedCutRules !=
null
535 && !pathnameLastUsedCutRules.isBlank())
537 GUIPreferences.lastCutRulesFile =
538 new File(pathnameLastUsedCutRules);
542 List<Vertex> fragments;
551 JOptionPane.showMessageDialog(
btnChop,String.format(
552 "<html><body width='%1s'"
553 +
"Could not complete fragmentation. Hint: "
554 + e.getMessage() +
"</html>", 400),
556 JOptionPane.ERROR_MESSAGE,
557 UIManager.getIcon(
"OptionPane.errorIcon"));
562 for (
Vertex frag : fragments)
569 if (fragments.size() < 1 || (fragments.size() == 1 &&
573 "<html>Fragmentation produced no fragments!</html>",
575 JOptionPane.WARNING_MESSAGE,
576 UIManager.getIcon(
"OptionPane.warningIcon"));
583 String[] options =
new String[]{
"All",
586 String txt =
"<html><body width='%1s'>Fragmentation produced "
587 + fragments.size() +
" fragments. Do you want to "
588 +
"append all or select some?"
590 int answer = JOptionPane.showOptionDialog(
btnAddVrtx,
591 String.format(txt,200),
592 "Append Building Blocks",
593 JOptionPane.DEFAULT_OPTION,
594 JOptionPane.QUESTION_MESSAGE,
595 UIManager.getIcon(
"OptionPane.warningIcon"),
611 List<Vertex> selectedVrtxs =
612 new ArrayList<Vertex>();
616 vrtxSelector.
load(fragments, 0);
619 if (selected !=
null)
621 @SuppressWarnings(
"unchecked")
622 List<ArrayList<Integer>> selList =
623 (ArrayList<ArrayList<Integer>>) selected;
624 for (ArrayList<Integer> pair : selList)
626 selectedVrtxs.add(fragments.get(pair.get(0)));
642 btnTmplBldChop.setToolTipText(String.format(
"<html><body width='%1s'>"
643 +
"Chops the current structure according to a given graph template expected to be a substructure of the current structure.</html>", 400));
645 public void actionPerformed(ActionEvent event) {
654 if (inFile ==
null || inFile.getAbsolutePath().equals(
""))
659 List<DGraph> fragmentationTmpls =
new ArrayList<>();
663 }
catch (Throwable e)
666 "<html><body width='%1s'"
667 +
"Could not read template file. Hint: "
668 + e.getMessage() +
"</html>", 400),
670 JOptionPane.ERROR_MESSAGE,
671 UIManager.getIcon(
"OptionPane.errorIcon"));
675 if (fragmentationTmpls.size() == 0)
678 "<html>No graphs found in file '"
679 + inFile +
"'.</html>",
681 JOptionPane.ERROR_MESSAGE,
682 UIManager.getIcon(
"OptionPane.errorIcon"));
690 List<Vertex> fragments;
699 JOptionPane.showMessageDialog(
btnChop,String.format(
700 "<html><body width='%1s'"
701 +
"Could not complete fragmentation. Hint: "
702 + e.getMessage() +
"</html>", 400),
704 JOptionPane.ERROR_MESSAGE,
705 UIManager.getIcon(
"OptionPane.errorIcon"));
710 for (
Vertex frag : fragments)
717 if (fragments.size() < 1 || (fragments.size() == 1 &&
721 "<html>Fragmentation produced no fragments!</html>",
723 JOptionPane.WARNING_MESSAGE,
724 UIManager.getIcon(
"OptionPane.warningIcon"));
731 String[] options =
new String[]{
"All",
734 String txt =
"<html><body width='%1s'>Fragmentation produced "
735 + fragments.size() +
" fragments. Do you want to "
736 +
"append all or select some?"
738 int answer = JOptionPane.showOptionDialog(
btnAddVrtx,
739 String.format(txt,200),
740 "Append Building Blocks",
741 JOptionPane.DEFAULT_OPTION,
742 JOptionPane.QUESTION_MESSAGE,
743 UIManager.getIcon(
"OptionPane.warningIcon"),
759 List<Vertex> selectedVrtxs =
760 new ArrayList<Vertex>();
764 vrtxSelector.
load(fragments, 0);
767 if (selected !=
null)
769 @SuppressWarnings(
"unchecked")
770 List<ArrayList<Integer>> selList =
771 (ArrayList<ArrayList<Integer>>) selected;
772 for (ArrayList<Integer> pair : selList)
774 selectedVrtxs.add(fragments.get(pair.get(0)));
790 btnDelSel.setToolTipText(
"<html>Removes all selected atoms from the "
791 +
"system.<br><br><b>WARNING:</b> this action cannot be "
793 btnDelSel.addActionListener(
new ActionListener() {
794 public void actionPerformed(ActionEvent e) {
795 ArrayList<IAtom> selectedAtms =
798 if (selectedAtms.size() == 0)
801 "<html>No atom selected! Click on atoms to select"
802 +
" them.<br>Click again to unselect.</html>",
804 JOptionPane.ERROR_MESSAGE,
805 UIManager.getIcon(
"OptionPane.errorIcon"));
828 btnSaveEdits.setToolTipText(
"<html>Save the current system replacing"
829 +
" <br>the original one in the loaded library.</html>");
831 public void actionPerformed(ActionEvent e) {
837 this.add(
ctrlPane, BorderLayout.EAST);
842 super.add(commandsPane, BorderLayout.SOUTH);
844 btnOpenVrtxs =
new JButton(
"Load Library of Building Blocks");
845 btnOpenVrtxs.setToolTipText(
"Reads building blocks or structures from "
848 public void actionPerformed(ActionEvent e) {
850 if (inFile ==
null || inFile.getAbsolutePath().equals(
""))
854 ArrayList<Vertex> vrtxLib =
new ArrayList<>();
857 }
catch (Exception e1) {
858 e1.printStackTrace();
860 "<html>Could not read building blocks from file"
861 +
"<br>'" + inFile +
"'"
862 +
"<br>Hint on cause: " + e1.getMessage()
865 JOptionPane.ERROR_MESSAGE,
866 UIManager.getIcon(
"OptionPane.errorIcon"));
870 if (vrtxLib.size() == 0)
873 "<html>No building blocks in file"
874 +
"<br>'" + inFile +
"'</html>",
876 JOptionPane.ERROR_MESSAGE,
877 UIManager.getIcon(
"OptionPane.errorIcon"));
885 JButton btnSaveVrtxs =
new JButton(
"Save Library of Building Blocks");
886 btnSaveVrtxs.setToolTipText(
"Write all building blocks to a file.");
887 btnSaveVrtxs.addActionListener(
new ActionListener() {
888 public void actionPerformed(ActionEvent e) {
891 if (fileAndFormat ==
null)
895 File outFile = fileAndFormat.
file;
906 ex.printStackTrace();
907 JOptionPane.showMessageDialog(btnSaveVrtxs,
908 "Could not write to '" + outFile +
"'! "
909 +
"Hint: "+ex.getMessage(),
911 JOptionPane.PLAIN_MESSAGE,
912 UIManager.getIcon(
"OptionPane.errorIcon"));
922 commandsPane.
add(btnSaveVrtxs);
924 JButton btnCanc =
new JButton(
"Close Tab");
925 btnCanc.setToolTipText(
"Closes this tab.");
927 commandsPane.
add(btnCanc);
929 JButton btnHelp =
new JButton(
"?");
930 btnHelp.setToolTipText(
"<html>Hover over the buttons and fields "
931 +
"to get a tip.</html>");
932 btnHelp.addActionListener(
new ActionListener() {
933 public void actionPerformed(ActionEvent e) {
934 String txt =
"<html><body width='%1s'>"
935 +
"<p>This tab allows to create, inspect, and edit "
936 +
"building blocks and "
937 +
"three-dimensional molecular fragments.</p>"
938 +
"<p>New fragments can be created starting from any "
939 +
"chemical structure that can be loaded from file or "
940 +
"generated from SMILES (SMILES-to-3D conversion "
941 +
"requires an Internet connection).</p>"
942 +
"<p>Any terminal atom (i.e., atoms that have only "
943 +
"one connected neighbor) can be transformed into "
944 +
"on attachment point (AP). Click on the atom to "
945 +
"select it, and press <code><b>Atom to AP</b></code>."
947 +
"<p>Attachment points are depicted in the molecular "
948 +
"viewer as yellow arrows in the 3D space, and their "
949 +
"attachment point class (APClass) is specified in "
950 +
"the table below the viewer. Double-click on a "
951 +
"specific APClass field to change its value.</p>"
953 +
"<p>Hover over buttons get a tip.</p>"
955 +
"<p>Right-click on the Jmol viewer will open the "
956 +
"Jmol menu. However, since Jmol cannot handle the "
957 +
"attachment points data. Therefore, Jmol "
958 +
"functionality should only be used on systems "
959 +
"that have no attachment points, or for alterations "
960 +
"of the molecular structure that do not change the "
961 +
"list of atoms au to the last atom decorated with an "
962 +
"attachment point.</p></html>";
963 JOptionPane.showMessageDialog(btnHelp,
964 String.format(txt, 400),
966 JOptionPane.PLAIN_MESSAGE);
969 commandsPane.
add(btnHelp);
987 boolean setMolToGraphSettings)
991 List<CuttingRule> defaultCuttingRules =
new ArrayList<CuttingRule>();
992 BufferedReader reader =
null;
996 reader =
new BufferedReader(
997 new InputStreamReader(classLoader.getResourceAsStream(
998 "data/cutting_rules")));
1005 }
catch (Exception e )
1007 e.printStackTrace();
1008 JOptionPane.showMessageDialog(parent,String.format(
1009 "<html><body width='%1s'>"
1010 +
"Could not read default cutting rules from "
1013 + e.getMessage() +
"</html>", 400),
1015 JOptionPane.ERROR_MESSAGE,
1016 UIManager.getIcon(
"OptionPane.errorIcon"));
1021 List<CuttingRule> customCuttingRules =
new ArrayList<CuttingRule>();
1022 boolean useDefaultCuttingRules =
true;
1029 customCuttingRules);
1030 useDefaultCuttingRules =
false;
1034 JOptionPane.showMessageDialog(parent,String.format(
1035 "<html><body width='%1s'"
1036 +
"Could not read last-used cutting rules from '"
1039 + e.getMessage() +
"</html>", 400),
1041 JOptionPane.ERROR_MESSAGE,
1042 UIManager.getIcon(
"OptionPane.errorIcon"));
1049 if (setMolToGraphSettings)
1052 defaultCuttingRules, customCuttingRules,
1053 useDefaultCuttingRules, parent, settings);
1056 defaultCuttingRules, customCuttingRules,
1057 useDefaultCuttingRules, parent, settings);
1060 crs.setVisible(
true);
1066 if (pathnameLastUsedCutRules !=
null
1067 && !pathnameLastUsedCutRules.isBlank())
1069 GUIPreferences.lastCutRulesFile =
new File(pathnameLastUsedCutRules);
1079 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1107 }
catch (Exception e) {
1108 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1109 e.printStackTrace();
1110 JOptionPane.showMessageDialog(
this,
1111 "<html>Could not read file '" + file.getAbsolutePath()
1112 +
"'!<br>Hint about reason: " + e.getCause() +
"</html>",
1114 JOptionPane.PLAIN_MESSAGE,
1115 UIManager.getIcon(
"OptionPane.errorIcon"));
1118 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1131 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1139 }
catch (Exception e) {
1140 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1159 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1170 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1172 ArrayList<Vertex> vrtxLib =
new ArrayList<>();
1175 }
catch (Exception e1) {
1176 e1.printStackTrace();
1178 "<html>Could not read building blocks from file"
1179 +
"<br>'" + file +
"'"
1180 +
"<br>Hint on cause: " + e1.getMessage()
1183 JOptionPane.ERROR_MESSAGE,
1184 UIManager.getIcon(
"OptionPane.errorIcon"));
1188 if (vrtxLib.size() == 0)
1191 "<html>No building blocks in file"
1192 +
"<br>'" + file +
"'</html>",
1194 JOptionPane.ERROR_MESSAGE,
1195 UIManager.getIcon(
"OptionPane.errorIcon"));
1199 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1210 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1213 boolean libFromScrtch =
false;
1216 libFromScrtch =
true;
1224 boolean addedOne =
false;
1225 if (fragments.size() > 0)
1244 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1245 JOptionPane.showMessageDialog(
this,
1246 "<html>No vertices to import from the given list.</html>",
1248 JOptionPane.PLAIN_MESSAGE,
1249 UIManager.getIcon(
"OptionPane.errorIcon"));
1251 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1268 JOptionPane.showMessageDialog(
this,
1269 "No list of building blocks loaded.",
1271 JOptionPane.PLAIN_MESSAGE,
1272 UIManager.getIcon(
"OptionPane.errorIcon"));
1332 str = str +
" " + atm.getSymbol()
1335 System.out.println(
"Connected atoms: "+str);
1337 JOptionPane.showMessageDialog(
this,
1338 "<html>Atom "+ trgAtm.getSymbol()
1340 +
" has zero or more than one neighbour.<br>I can only "
1342 +
" that have one and only one neighbour.</html>",
1344 JOptionPane.ERROR_MESSAGE,
1345 UIManager.getIcon(
"OptionPane.errorIcon"));
1351 srcAtm.getBond(trgAtm).getOrder().toString());
1355 Point3d vector =
new Point3d();
1356 vector.x = srcP3d.x + (trgP3d.x - srcP3d.x);
1357 vector.y = srcP3d.y + (trgP3d.y - srcP3d.y);
1358 vector.z = srcP3d.z + (trgP3d.z - srcP3d.z);
1361 String[] parts = ruleAndSubClass.split(
1367 Integer.parseInt(parts[1]), bt), vector);
1369 e.printStackTrace();
1370 JOptionPane.showMessageDialog(
this,
1371 "<html>Could not make AP.<br>Possible cause: "
1372 + e.getMessage() +
"</html>",
1374 JOptionPane.ERROR_MESSAGE,
1375 UIManager.getIcon(
"OptionPane.errorIcon"));
1390 ArrayList<IBond> bnsToDel =
new ArrayList<IBond>();
1391 for (IAtom atm : atmsToDels)
1393 for (IBond bnd : frag.
bonds())
1395 if (bnd.contains(atm))
1401 for (IBond bnd : bnsToDel)
1405 for (IAtom atm : atmsToDels)
1433 this.inEnabled = var;
1474 .getTextField().setEditable(
true);
1476 .getTextField().setForeground(Color.BLACK);
1499 .getTextField().setEditable(
false);
1501 .getTextField().setForeground(Color.GRAY);
1521 String[] options =
new String[]{
"Yes",
"No"};
1522 int res = JOptionPane.showOptionDialog(
this,
1523 "<html>Removing unsaved vertex?",
1525 JOptionPane.DEFAULT_OPTION,
1526 JOptionPane.QUESTION_MESSAGE,
1527 UIManager.getIcon(
"OptionPane.warningIcon"),
1559 navigSpinner.setModel(
new SpinnerNumberModel(0,0,0,1));
1578 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1584 for (
int i=0; i<tabModel.getRowCount(); i++)
1586 int apId = ((Integer) tabModel.getValueAt(i, 0)).intValue();
1587 String currApClass = tabModel.getValueAt(i, 1).toString();
1592 apcDefiner.setTitle(
"Confirm APClass on AP #"+i);
1597 Object[] pair = (Object[]) chosen;
1598 currApClass = pair[0].toString();
1600 currApClass =
"dafaultAPClass:0";
1603 Map<Integer, AttachmentPoint> mapAPs =
1606 if (mapAPs.containsKey(apId))
1608 String origApClass = mapAPs.get(apId).getAPClass().toString();
1609 if (!origApClass.equals(currApClass))
1612 mapAPs.get(apId).setAPClass(currApClass);
1616 e.printStackTrace();
1618 "<html>Could not save due to errors setting a "
1619 +
"new APClass.<br>Please report this to the "
1620 +
"DENOPTIM team.</html>",
1622 JOptionPane.PLAIN_MESSAGE,
1623 UIManager.getIcon(
"OptionPane.errorIcon"));
1631 "<html>Could not save due to mistmatch between AP "
1632 +
"table and map.<br>Please report this to the "
1633 +
"DENOPTIM team.</html>",
1635 JOptionPane.PLAIN_MESSAGE,
1636 UIManager.getIcon(
"OptionPane.errorIcon"));
1649 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1658 }
catch (Throwable t) {
1669 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1683 boolean singleSelection)
1686 DefaultListModel<String> apClassLstModel =
1687 new DefaultListModel<String>();
1688 JList<String> apClassList =
new JList<String>(apClassLstModel);
1691 apClassLstModel.addElement(apc);
1694 apClassLstModel.addElement(
1695 "<html><b><i>Define a new APClass...<i></b></html>");
1696 if (singleSelection)
1698 apClassList.setSelectionMode(
1699 ListSelectionModel.SINGLE_SELECTION);
1701 apClassList.setSelectionMode(
1702 ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
1704 if (apClassList.getModel().getSize() == 1)
1706 apClassList.setSelectedIndex(0);
1708 apClassList.setSelectedIndex(apClassLstModel.getSize()-1);
1712 JPanel chooseApPanel =
new JPanel();
1713 JLabel header =
new JLabel(
"Choose APClass:");
1714 JScrollPane apClassScroll =
new JScrollPane(apClassList);
1715 chooseApPanel.add(header);
1716 chooseApPanel.add(apClassScroll);
1718 int res = JOptionPane.showConfirmDialog(parent,
1720 "Choose APClasses to Add",
1721 JOptionPane.OK_CANCEL_OPTION,
1722 JOptionPane.PLAIN_MESSAGE,
1724 if (res != JOptionPane.OK_OPTION)
1726 return new ArrayList<APClass>();
1730 ArrayList<APClass> selectedSPCs =
new ArrayList<APClass>();
1731 int[] selectedIds = apClassList.getSelectedIndices();
1732 if (selectedIds.length > 0)
1734 for (
int ii=0; ii<selectedIds.length; ii++)
1737 Integer idAPC = selectedIds[ii];
1740 if (idAPC.intValue() == (apClassLstModel.size()-1))
1748 Object[] pair = (Object[]) chosen;
1753 apc =
APClass.
make(apClassLstModel.getElementAt(idAPC));
1755 }
catch (Exception e1) {
1759 selectedSPCs.add(apc);
1762 return selectedSPCs;
1776 String title,
boolean mustReply, JComponent parent)
1782 if (currApRule !=
"")
1784 preStr =
"APRule '" + currApRule +
"' is not valid!<br>"
1785 +
"The valid syntax for APClass is:<br><br><code>APRule"
1786 + DENOPTIMConstants.SEPARATORAPPROPSCL
1787 +
"subClass</code><br><br> where "
1788 +
"<ul><li><code>APRule</code>"
1789 +
" is the string you should provide now, and is "
1790 +
"typically any string with no spaces,</li>"
1791 +
"<li><code>subClass</code> is an integer.</ul>";
1794 currApRule = JOptionPane.showInputDialog(parent,String.format(
1795 "<html><body width='%1s'>" + preStr
1796 +
" Please, provide a valid APClass rule string: </html>",
1799 JOptionPane.PLAIN_MESSAGE);
1801 if (currApRule ==
null)
General set of constants used in DENOPTIM.
static final String ATMPROPAPS
String tag of Atom property used to store attachment points.
static final String APSTAG
SDF tag defining attachment points.
static final String SEPARATORAPPROPSCL
Separator between APClass and APSubClass and coordinates.
static void addToRecentFiles(String fileName, FileFormat ff)
Appends an entry to the list of recent files.
static List< String > getAllAPClassesAsString()
Returns the list of the names of all APClasses.
static boolean isValidAPRuleString(String s)
Evaluates the given string as a candidate attachment point rule, i.e., as name of a fragmentation rul...
static APClass make(String ruleAndSubclass)
Creates an APClass if it does not exist already, or returns the reference to the existing instance.
An empty vertex has the behaviors of a vertex, but has no molecular structure.
Class representing a continuously connected portion of chemical object holding attachment points.
IBond removeBond(int position)
List< IAtom > getConnectedAtomsList(IAtom atom)
AttachmentPoint addAPOnAtom(IAtom srcAtm, APClass apc, Point3d vector)
Add an attachment point to the specifies atom.
List< AttachmentPoint > getAttachmentPoints()
ArrayList< AttachmentPoint > getAPsFromAtom(IAtom srcAtm)
void removeAtom(IAtom atom)
void updateAPs()
Changes the properties of each APs as to reflect the current atom list.
Iterable< IBond > bonds()
int getConnectedAtomsCount(IAtom atom)
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
abstract IAtomContainer getIAtomContainer()
A modal dialog to define parameters for fragmentation and fragment filtering.
void setPreDefinedAPClass(String text)
Sets the content of the text field with the given predefined text.
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 pickFile(Component parent)
GUI component to provide pathname where to save stuff.
static FileAndFormat pickFileForSavingVertexes(Component parent)
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 result
The result to be returned once the dialog is closed.
Object showDialog()
Shows the dialog and restrains the modality to it, until the dialog gets closed.
The collection of tunable preferences.
static File lastCutRulesFile
File with last used cutting rules.
void setEnabled(boolean var)
Enables/disable the listener.
void stateChanged(ChangeEvent event)
A panel with a viewer capable of visualising DENOPTIM fragments and allows to create and edit fragmen...
void updateVrtxListSpinner()
void clearCurrentSystem()
static String ensureGoodAPRuleString(String currApRule, String title, boolean mustReply, JComponent parent)
Forces the user to specify a properly formatted APRule, i.e., the first component of an APClass.
void saveUnsavedChanges()
ArrayList< Vertex > verticesLibrary
The currently loaded list of fragments.
final VrtxSpinnerChangeEvent vrtxSpinnerListener
Vertex vertex
The currently loaded vertex.
void importStructureFromSMILES(String smiles)
Imports the given SMILES into the viewer.
void deprotectEditedSystem()
static AtomicInteger prepVrtxTabUID
Unique identified for instances of this inspector.
void importVerticesFromFile(File file)
Imports fragments from a file.
VertexViewPanel vertexViewer
void importVertices(List< Vertex > fragments)
Imports vertices.
boolean convertAtomToAP(IAtom trgAtm, String ruleAndSubClass)
Removes an atom and replaces it with an attachment point.
boolean unsavedChanges
Flag signaling that loaded data has changes since last save.
void importStructureFromFile(File file)
int currVrtxIdx
The index of the currently loaded fragment [0–(n-1)}.
boolean hasUnsavedChanges()
Check whether there are unsaved changes.
static List< APClass > choseOrCreateNewAPClass(JComponent parent, boolean singleSelection)
Runs a dialog aimed at selecting an existing APClass or defining a new one.
GUIVertexInspector(GUIMainPanel mainPanel)
Constructor.
void initialize()
Initialize the panel and add buttons.
void protectEditedSystem()
void loadCurrentVrtxIdxToViewer()
Loads the fragments corresponding to the field index.
void removeAtoms(ArrayList< IAtom > atmsToDels)
static final long serialVersionUID
Version UID.
static boolean dialogToDefineCuttingRules(FragmenterParameters settings, ClassLoader classLoader, Component parent, boolean setMolToGraphSettings)
Starts a dialog to define the on-the-fly fragmentation settings.
void activateTabEditsListener(boolean var)
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 ...
A panel for visualizing vertices.
void clearCurrentSystem()
Removes the currently visualized molecule and AP table.
boolean hasUnsavedAPEdits()
Check for unsaved edits to the AP data.
DefaultTableModel getAPTableModel()
void activateTabEditsListener(boolean var)
Allows to activate and deactivate the listener.
Map< Integer, AttachmentPoint > getActiveMapAPs()
Returns the map of attachment points in the currently active viewer.
void deprotectEdits()
Overrides the flag signaling unsaved edits to saying that there are no altered data.
void loadVertexToViewer(Vertex v)
Loads the given vertex to this viewer.
Vertex getLoadedStructure()
Returns the currently loaded vertex.
void loadPlainStructure(IAtomContainer mol)
Loads a structure in the Jmol viewer.
boolean loadSMILES(String smiles)
Loads a molecule build from a smiles string.
void setSwitchable(boolean switchable)
Enable/disable switch-able view.
ArrayList< IAtom > getAtomsSelectedFromJMol()
Identifies the atoms that are selected in the Jmol viewer.
void clearMolecularViewer(boolean dataIsComing)
Clears the molecular viewer.
Utility methods for input/output.
static File writeVertexesToFile(File file, FileFormat format, List< Vertex > vertexes)
Writes vertexes to file.
static void readCuttingRules(BufferedReader reader, List< CuttingRule > cutRules, String source)
Read cutting rules from a stream.
static ArrayList< DGraph > readDENOPTIMGraphsFromFile(File inFile)
Reads a list of DGraphs from file.
static ArrayList< Vertex > readVertexes(File file, Vertex.BBType bbt)
Reads Vertexes from any file that can contain such items.
static List< IAtomContainer > readAllAtomContainers(File file)
Returns a single collection with all atom containers found in a file of any format.
Logger getLogger()
Get the name of the program specific logger.
Logger startConsoleLogger(String loggerIdentifier)
Starts a program-specific logger that prints to System.err stream.
Randomizer getRandomizer()
Returns the current program-specific randomizer.
Parameters controlling execution of the fragmenter.
double getLinearAngleLimit()
String getCuttingRulesFilePathname()
void setFragmentationTmpls(List< DGraph > fragmentationTmpls)
Sets the list of graph templates for fragmentation.
List< DGraph > getFragmentationTmpls()
List< CuttingRule > getCuttingRules()
Toll to add/remove dummy atoms from linearities or multi-hapto sites.
static void addDummiesOnLinearities(Fragment frag, double angLim)
Append dummy atoms on otherwise linear arrangements of atoms.
Utilities for molecule conversion.
static Point3d getPoint3d(IAtom atm)
Return the 3D coordinates, if present.
Possible chemical bond types an edge can represent.
The type of building block.
Interface for all vertex viewers that intend to allow selection of attachment points.
final String APDATACHANGEEVENT