Skip to content

Commit

Permalink
Added reaction template file option to provide custom query reaction …
Browse files Browse the repository at this point in the history
…templates to editor; some minor adaptions
  • Loading branch information
thsa committed Nov 8, 2022
1 parent f83b589 commit 1d55833
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 8 deletions.
Binary file modified lib/molviewerlib.jar
Binary file not shown.
45 changes: 43 additions & 2 deletions src/com/actelion/research/datawarrior/DataWarrior.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.lang.reflect.Method;
import java.security.CodeSource;
import java.util.ArrayList;
Expand All @@ -62,6 +61,7 @@ public abstract class DataWarrior implements WindowFocusListener {
public static final String[] RESOURCE_DIR = { "Reference", "Example", "Tutorial" };
public static final String MACRO_DIR = "Macro";
public static final String PLUGIN_DIR = "Plugin";
public static final String QUERY_REACTION_TEMPLATE_FILE = "template/reactionqueries.txt";

private boolean mIsCapkaAvailable;

Expand Down Expand Up @@ -270,6 +270,47 @@ public void initialize() {
catch (Throwable t) {
t.printStackTrace();
}

initializeCustomTemplates();
}

private void initializeCustomTemplates() {
File rtf = resolveResourcePath(QUERY_REACTION_TEMPLATE_FILE);
if (rtf != null) {
try {
ArrayList<String[]> list = new ArrayList<>();
BufferedReader reader = new BufferedReader(new FileReader(rtf));
String[] keyAndValue = parseTemplateLine(reader);
if (keyAndValue != null
&& keyAndValue[0].equals(GenericEditorArea.TEMPLATE_TYPE_KEY)
&& keyAndValue[1].equals(GenericEditorArea.TEMPLATE_TYPE_REACTION_QUERIES)) {
keyAndValue = parseTemplateLine(reader);
while (keyAndValue != null) {
list.add(keyAndValue);
keyAndValue = parseTemplateLine(reader);
}
}
reader.close();
if (list.size() != 0)
GenericEditorArea.setReactionQueryTemplates(list.toArray(new String[0][]));
}
catch (IOException ioe) {}
}
}

private String[] parseTemplateLine(BufferedReader reader) throws IOException {
String line = reader.readLine();
if (line == null)
return null;

int index = line.indexOf(':');
if (index == -1)
return null;

String[] template = new String[2];
template[0] = line.substring(0, index).trim();
template[1] = line.substring(index+1).trim();
return template;
}

public void checkVersion(boolean showUpToDateMessage) {
Expand Down
2 changes: 1 addition & 1 deletion src/com/actelion/research/datawarrior/StandardMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ else if (source == jMenuFileOpenMacro)
else if (source == jMenuFileOpenMDLReactions)
new DETaskOpenMDLReactionDatabase(mApplication).defineAndRun();
else if (source == jMenuFileMerge)
new DETaskMergeFile(mParentFrame, true).defineAndRun();
new DETaskMergeFile(mParentFrame).defineAndRun();
else if (source == jMenuFileAppend) {
if (mParentFrame.getTableModel().getTotalRowCount() == 0)
JOptionPane.showMessageDialog(mParentFrame, "You cannot append a file to an empty table. Use 'Open File...' instead.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public AbstractTask createTaskFromCode(DEFrame frame, String taskCode) {
: codeMatches(taskCode, DETaskJumpToReferenceRow.TASK_NAME) ? new DETaskJumpToReferenceRow(frame, mainPane)
: codeMatches(taskCode, DETaskMapReactions.TASK_NAME) ? new DETaskMapReactions(frame)
: codeMatches(taskCode, DETaskMergeColumns.TASK_NAME) ? new DETaskMergeColumns(frame)
: codeMatches(taskCode, DETaskMergeFile.TASK_NAME) ? new DETaskMergeFile(frame, false)
: codeMatches(taskCode, DETaskMergeFile.TASK_NAME) ? new DETaskMergeFile(frame)
: codeMatches(taskCode, DETaskNew2DView.TASK_NAME) ? new DETaskNew2DView(frame, mainPane,null)
: codeMatches(taskCode, DETaskNew3DView.TASK_NAME) ? new DETaskNew3DView(frame, mainPane,null)
: codeMatches(taskCode, DETaskNewCardsView.TASK_NAME) ? new DETaskNewCardsView(frame, mainPane,null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ private void addConformersToQueue(int row, StereoMolecule mol) throws Exception
if (mLargestFragmentOnly) {
mol.stripSmallFragments();
if (mNeutralizeLargestFragment)
new MoleculeNeutralizer().neutralizeChargedMolecule(mol);
MoleculeNeutralizer.neutralizeChargedMolecule(mol);
}

// don't create any protonation states
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void processRow(int row, int firstNewColumn, StereoMolecule containerMol,
private void handleMolecule(StereoMolecule mol) {
mol.stripSmallFragments();
if (mNeutralizeFragment)
new MoleculeNeutralizer().neutralizeChargedMolecule(mol);
MoleculeNeutralizer.neutralizeChargedMolecule(mol);
if (mAsSubstructure)
mol.setFragment(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public void processRow(int row, int firstNewColumn, StereoMolecule containerMol,
private void handleMolecule(StereoMolecule mol) {
mol.stripSmallFragments();
if (mProtonateFragment) {
new MoleculeNeutralizer().neutralizeChargedMolecule(mol);
MoleculeNeutralizer.neutralizeChargedMolecule(mol);
assignLikelyProtonationStates(mol);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class DETaskMergeFile extends AbstractTask implements TaskConstantsMergeF
private UIDelegateMergeFile mUIDelegate;
private CompoundTableLoader mLoader;

public DETaskMergeFile(DEFrame parent, boolean isInteractive) {
public DETaskMergeFile(DEFrame parent) {
super(parent, true);
// All tasks that use CompoundTableLoader need to run in an own thread if they run in a macro
// to prevent the CompoundTableLoader to run processData() in a new thread without waiting
Expand Down

0 comments on commit 1d55833

Please sign in to comment.