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;
700 JOptionPane.showMessageDialog(
btnChop,String.format(
701 "<html><body width='%1s'"
702 +
"Could not complete fragmentation. Hint: "
703 + e.getMessage() +
"</html>", 400),
705 JOptionPane.ERROR_MESSAGE,
706 UIManager.getIcon(
"OptionPane.errorIcon"));
711 for (
Vertex frag : fragments)
718 if (fragments.size() < 1 || (fragments.size() == 1 &&
722 "<html>Fragmentation produced no fragments!</html>",
724 JOptionPane.WARNING_MESSAGE,
725 UIManager.getIcon(
"OptionPane.warningIcon"));
732 String[] options =
new String[]{
"All",
735 String txt =
"<html><body width='%1s'>Fragmentation produced "
736 + fragments.size() +
" fragments. Do you want to "
737 +
"append all or select some?"
739 int answer = JOptionPane.showOptionDialog(
btnAddVrtx,
740 String.format(txt,200),
741 "Append Building Blocks",
742 JOptionPane.DEFAULT_OPTION,
743 JOptionPane.QUESTION_MESSAGE,
744 UIManager.getIcon(
"OptionPane.warningIcon"),
760 List<Vertex> selectedVrtxs =
761 new ArrayList<Vertex>();
765 vrtxSelector.
load(fragments, 0);
768 if (selected !=
null)
770 @SuppressWarnings(
"unchecked")
771 List<ArrayList<Integer>> selList =
772 (ArrayList<ArrayList<Integer>>) selected;
773 for (ArrayList<Integer> pair : selList)
775 selectedVrtxs.add(fragments.get(pair.get(0)));
791 btnDelSel.setToolTipText(
"<html>Removes all selected atoms from the "
792 +
"system.<br><br><b>WARNING:</b> this action cannot be "
794 btnDelSel.addActionListener(
new ActionListener() {
795 public void actionPerformed(ActionEvent e) {
796 ArrayList<IAtom> selectedAtms =
799 if (selectedAtms.size() == 0)
802 "<html>No atom selected! Click on atoms to select"
803 +
" them.<br>Click again to unselect.</html>",
805 JOptionPane.ERROR_MESSAGE,
806 UIManager.getIcon(
"OptionPane.errorIcon"));
829 btnSaveEdits.setToolTipText(
"<html>Save the current system replacing"
830 +
" <br>the original one in the loaded library.</html>");
832 public void actionPerformed(ActionEvent e) {
838 this.add(
ctrlPane, BorderLayout.EAST);
843 super.add(commandsPane, BorderLayout.SOUTH);
845 btnOpenVrtxs =
new JButton(
"Load Library of Building Blocks");
846 btnOpenVrtxs.setToolTipText(
"Reads building blocks or structures from "
849 public void actionPerformed(ActionEvent e) {
851 if (inFile ==
null || inFile.getAbsolutePath().equals(
""))
855 ArrayList<Vertex> vrtxLib =
new ArrayList<>();
858 }
catch (Exception e1) {
859 e1.printStackTrace();
861 "<html>Could not read building blocks from file"
862 +
"<br>'" + inFile +
"'"
863 +
"<br>Hint on cause: " + e1.getMessage()
866 JOptionPane.ERROR_MESSAGE,
867 UIManager.getIcon(
"OptionPane.errorIcon"));
871 if (vrtxLib.size() == 0)
874 "<html>No building blocks in file"
875 +
"<br>'" + inFile +
"'</html>",
877 JOptionPane.ERROR_MESSAGE,
878 UIManager.getIcon(
"OptionPane.errorIcon"));
886 JButton btnSaveVrtxs =
new JButton(
"Save Library of Building Blocks");
887 btnSaveVrtxs.setToolTipText(
"Write all building blocks to a file.");
888 btnSaveVrtxs.addActionListener(
new ActionListener() {
889 public void actionPerformed(ActionEvent e) {
892 if (fileAndFormat ==
null)
896 File outFile = fileAndFormat.
file;
907 ex.printStackTrace();
908 JOptionPane.showMessageDialog(btnSaveVrtxs,
909 "Could not write to '" + outFile +
"'! "
910 +
"Hint: "+ex.getMessage(),
912 JOptionPane.PLAIN_MESSAGE,
913 UIManager.getIcon(
"OptionPane.errorIcon"));
923 commandsPane.
add(btnSaveVrtxs);
925 JButton btnCanc =
new JButton(
"Close Tab");
926 btnCanc.setToolTipText(
"Closes this tab.");
928 commandsPane.
add(btnCanc);
930 JButton btnHelp =
new JButton(
"?");
931 btnHelp.setToolTipText(
"<html>Hover over the buttons and fields "
932 +
"to get a tip.</html>");
933 btnHelp.addActionListener(
new ActionListener() {
934 public void actionPerformed(ActionEvent e) {
935 String txt =
"<html><body width='%1s'>"
936 +
"<p>This tab allows to create, inspect, and edit "
937 +
"building blocks and "
938 +
"three-dimensional molecular fragments.</p>"
939 +
"<p>New fragments can be created starting from any "
940 +
"chemical structure that can be loaded from file or "
941 +
"generated from SMILES (SMILES-to-3D conversion "
942 +
"requires an Internet connection).</p>"
943 +
"<p>Any terminal atom (i.e., atoms that have only "
944 +
"one connected neighbor) can be transformed into "
945 +
"on attachment point (AP). Click on the atom to "
946 +
"select it, and press <code><b>Atom to AP</b></code>."
948 +
"<p>Attachment points are depicted in the molecular "
949 +
"viewer as yellow arrows in the 3D space, and their "
950 +
"attachment point class (APClass) is specified in "
951 +
"the table below the viewer. Double-click on a "
952 +
"specific APClass field to change its value.</p>"
954 +
"<p>Hover over buttons get a tip.</p>"
956 +
"<p>Right-click on the Jmol viewer will open the "
957 +
"Jmol menu. However, since Jmol cannot handle the "
958 +
"attachment points data. Therefore, Jmol "
959 +
"functionality should only be used on systems "
960 +
"that have no attachment points, or for alterations "
961 +
"of the molecular structure that do not change the "
962 +
"list of atoms au to the last atom decorated with an "
963 +
"attachment point.</p></html>";
964 JOptionPane.showMessageDialog(btnHelp,
965 String.format(txt, 400),
967 JOptionPane.PLAIN_MESSAGE);
970 commandsPane.
add(btnHelp);
988 boolean setMolToGraphSettings)
992 List<CuttingRule> defaultCuttingRules =
new ArrayList<CuttingRule>();
993 BufferedReader reader =
null;
997 reader =
new BufferedReader(
998 new InputStreamReader(classLoader.getResourceAsStream(
999 "data/cutting_rules")));
1006 }
catch (Exception e )
1008 e.printStackTrace();
1009 JOptionPane.showMessageDialog(parent,String.format(
1010 "<html><body width='%1s'>"
1011 +
"Could not read default cutting rules from "
1014 + e.getMessage() +
"</html>", 400),
1016 JOptionPane.ERROR_MESSAGE,
1017 UIManager.getIcon(
"OptionPane.errorIcon"));
1022 List<CuttingRule> customCuttingRules =
new ArrayList<CuttingRule>();
1023 boolean useDefaultCuttingRules =
true;
1030 customCuttingRules);
1031 useDefaultCuttingRules =
false;
1035 JOptionPane.showMessageDialog(parent,String.format(
1036 "<html><body width='%1s'"
1037 +
"Could not read last-used cutting rules from '"
1040 + e.getMessage() +
"</html>", 400),
1042 JOptionPane.ERROR_MESSAGE,
1043 UIManager.getIcon(
"OptionPane.errorIcon"));
1050 if (setMolToGraphSettings)
1053 defaultCuttingRules, customCuttingRules,
1054 useDefaultCuttingRules, parent, settings);
1057 defaultCuttingRules, customCuttingRules,
1058 useDefaultCuttingRules, parent, settings);
1061 crs.setVisible(
true);
1067 if (pathnameLastUsedCutRules !=
null
1068 && !pathnameLastUsedCutRules.isBlank())
1070 GUIPreferences.lastCutRulesFile =
new File(pathnameLastUsedCutRules);
1080 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1108 }
catch (Exception e) {
1109 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1110 e.printStackTrace();
1111 JOptionPane.showMessageDialog(
this,
1112 "<html>Could not read file '" + file.getAbsolutePath()
1113 +
"'!<br>Hint about reason: " + e.getCause() +
"</html>",
1115 JOptionPane.PLAIN_MESSAGE,
1116 UIManager.getIcon(
"OptionPane.errorIcon"));
1119 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1132 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1140 }
catch (Exception e) {
1141 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1160 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1171 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1173 ArrayList<Vertex> vrtxLib =
new ArrayList<>();
1176 }
catch (Exception e1) {
1177 e1.printStackTrace();
1179 "<html>Could not read building blocks from file"
1180 +
"<br>'" + file +
"'"
1181 +
"<br>Hint on cause: " + e1.getMessage()
1184 JOptionPane.ERROR_MESSAGE,
1185 UIManager.getIcon(
"OptionPane.errorIcon"));
1189 if (vrtxLib.size() == 0)
1192 "<html>No building blocks in file"
1193 +
"<br>'" + file +
"'</html>",
1195 JOptionPane.ERROR_MESSAGE,
1196 UIManager.getIcon(
"OptionPane.errorIcon"));
1200 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1211 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1214 boolean libFromScrtch =
false;
1217 libFromScrtch =
true;
1225 boolean addedOne =
false;
1226 if (fragments.size() > 0)
1245 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1246 JOptionPane.showMessageDialog(
this,
1247 "<html>No vertices to import from the given list.</html>",
1249 JOptionPane.PLAIN_MESSAGE,
1250 UIManager.getIcon(
"OptionPane.errorIcon"));
1252 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1269 JOptionPane.showMessageDialog(
this,
1270 "No list of building blocks loaded.",
1272 JOptionPane.PLAIN_MESSAGE,
1273 UIManager.getIcon(
"OptionPane.errorIcon"));
1333 str = str +
" " + atm.getSymbol()
1336 System.out.println(
"Connected atoms: "+str);
1338 JOptionPane.showMessageDialog(
this,
1339 "<html>Atom "+ trgAtm.getSymbol()
1341 +
" has zero or more than one neighbour.<br>I can only "
1343 +
" that have one and only one neighbour.</html>",
1345 JOptionPane.ERROR_MESSAGE,
1346 UIManager.getIcon(
"OptionPane.errorIcon"));
1352 srcAtm.getBond(trgAtm).getOrder().toString());
1356 Point3d vector =
new Point3d();
1357 vector.x = srcP3d.x + (trgP3d.x - srcP3d.x);
1358 vector.y = srcP3d.y + (trgP3d.y - srcP3d.y);
1359 vector.z = srcP3d.z + (trgP3d.z - srcP3d.z);
1362 String[] parts = ruleAndSubClass.split(
1368 Integer.parseInt(parts[1]), bt), vector);
1370 e.printStackTrace();
1371 JOptionPane.showMessageDialog(
this,
1372 "<html>Could not make AP.<br>Possible cause: "
1373 + e.getMessage() +
"</html>",
1375 JOptionPane.ERROR_MESSAGE,
1376 UIManager.getIcon(
"OptionPane.errorIcon"));
1391 ArrayList<IBond> bnsToDel =
new ArrayList<IBond>();
1392 for (IAtom atm : atmsToDels)
1394 for (IBond bnd : frag.
bonds())
1396 if (bnd.contains(atm))
1402 for (IBond bnd : bnsToDel)
1406 for (IAtom atm : atmsToDels)
1434 this.inEnabled = var;
1475 .getTextField().setEditable(
true);
1477 .getTextField().setForeground(Color.BLACK);
1500 .getTextField().setEditable(
false);
1502 .getTextField().setForeground(Color.GRAY);
1522 String[] options =
new String[]{
"Yes",
"No"};
1523 int res = JOptionPane.showOptionDialog(
this,
1524 "<html>Removing unsaved vertex?",
1526 JOptionPane.DEFAULT_OPTION,
1527 JOptionPane.QUESTION_MESSAGE,
1528 UIManager.getIcon(
"OptionPane.warningIcon"),
1560 navigSpinner.setModel(
new SpinnerNumberModel(0,0,0,1));
1579 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1585 for (
int i=0; i<tabModel.getRowCount(); i++)
1587 int apId = ((Integer) tabModel.getValueAt(i, 0)).intValue();
1588 String currApClass = tabModel.getValueAt(i, 1).toString();
1593 apcDefiner.setTitle(
"Confirm APClass on AP #"+i);
1598 Object[] pair = (Object[]) chosen;
1599 currApClass = pair[0].toString();
1601 currApClass =
"dafaultAPClass:0";
1604 Map<Integer, AttachmentPoint> mapAPs =
1607 if (mapAPs.containsKey(apId))
1609 String origApClass = mapAPs.get(apId).getAPClass().toString();
1610 if (!origApClass.equals(currApClass))
1613 mapAPs.get(apId).setAPClass(currApClass);
1617 e.printStackTrace();
1619 "<html>Could not save due to errors setting a "
1620 +
"new APClass.<br>Please report this to the "
1621 +
"DENOPTIM team.</html>",
1623 JOptionPane.PLAIN_MESSAGE,
1624 UIManager.getIcon(
"OptionPane.errorIcon"));
1632 "<html>Could not save due to mistmatch between AP "
1633 +
"table and map.<br>Please report this to the "
1634 +
"DENOPTIM team.</html>",
1636 JOptionPane.PLAIN_MESSAGE,
1637 UIManager.getIcon(
"OptionPane.errorIcon"));
1650 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1659 }
catch (Throwable t) {
1670 this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1684 boolean singleSelection)
1687 DefaultListModel<String> apClassLstModel =
1688 new DefaultListModel<String>();
1689 JList<String> apClassList =
new JList<String>(apClassLstModel);
1692 apClassLstModel.addElement(apc);
1695 apClassLstModel.addElement(
1696 "<html><b><i>Define a new APClass...<i></b></html>");
1697 if (singleSelection)
1699 apClassList.setSelectionMode(
1700 ListSelectionModel.SINGLE_SELECTION);
1702 apClassList.setSelectionMode(
1703 ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
1705 if (apClassList.getModel().getSize() == 1)
1707 apClassList.setSelectedIndex(0);
1709 apClassList.setSelectedIndex(apClassLstModel.getSize()-1);
1713 JPanel chooseApPanel =
new JPanel();
1714 JLabel header =
new JLabel(
"Choose APClass:");
1715 JScrollPane apClassScroll =
new JScrollPane(apClassList);
1716 chooseApPanel.add(header);
1717 chooseApPanel.add(apClassScroll);
1719 int res = JOptionPane.showConfirmDialog(parent,
1721 "Choose APClasses to Add",
1722 JOptionPane.OK_CANCEL_OPTION,
1723 JOptionPane.PLAIN_MESSAGE,
1725 if (res != JOptionPane.OK_OPTION)
1727 return new ArrayList<APClass>();
1731 ArrayList<APClass> selectedSPCs =
new ArrayList<APClass>();
1732 int[] selectedIds = apClassList.getSelectedIndices();
1733 if (selectedIds.length > 0)
1735 for (
int ii=0; ii<selectedIds.length; ii++)
1738 Integer idAPC = selectedIds[ii];
1741 if (idAPC.intValue() == (apClassLstModel.size()-1))
1749 Object[] pair = (Object[]) chosen;
1754 apc =
APClass.
make(apClassLstModel.getElementAt(idAPC));
1756 }
catch (Exception e1) {
1760 selectedSPCs.add(apc);
1763 return selectedSPCs;
1777 String title,
boolean mustReply, JComponent parent)
1783 if (currApRule !=
"")
1785 preStr =
"APRule '" + currApRule +
"' is not valid!<br>"
1786 +
"The valid syntax for APClass is:<br><br><code>APRule"
1787 + DENOPTIMConstants.SEPARATORAPPROPSCL
1788 +
"subClass</code><br><br> where "
1789 +
"<ul><li><code>APRule</code>"
1790 +
" is the string you should provide now, and is "
1791 +
"typically any string with no spaces,</li>"
1792 +
"<li><code>subClass</code> is an integer.</ul>";
1795 currApRule = JOptionPane.showInputDialog(parent,String.format(
1796 "<html><body width='%1s'>" + preStr
1797 +
" Please, provide a valid APClass rule string: </html>",
1800 JOptionPane.PLAIN_MESSAGE);
1802 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()
int getMaxBufferShellSize()
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