Skip to content

Commit 6a5c78c

Browse files
author
Michael Wenk
authored
Merge pull request #5 from michaelwenk/fix-bidirectional-BOND-command
fix: avoid bidirectional BOND commands in PyLSD input file; close #4
2 parents 99e2911 + f78392e commit 6a5c78c

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/casekit/nmr/elucidation/lsd/PyLSDInputFileBuilder.java

+24-12
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ private static Map<String, StringBuilder> buildStringBuilderMap(
9191
int counter, firstOfEquivalenceIndexPyLSD;
9292
Set<Integer> groupMembers; // use as a Set to remove the actual value and not at a list index
9393
MolecularConnectivity molecularConnectivityGroupMember, molecularConnectivityHeavyAtom;
94+
final Map<Integer, Set<Integer>> addedBONDPairs = new HashMap<>();
9495
final Set<Integer> addedKeysSHIH = new HashSet<>();
9596
for (final int correlationIndex : molecularConnectivityMap.keySet()) {
9697
firstOfEquivalenceIndexPyLSD = -1;
@@ -234,18 +235,29 @@ private static Map<String, StringBuilder> buildStringBuilderMap(
234235
!= null) {
235236
stringList = stringListMap.get("BOND");
236237
for (final int bondedIndexInPyLSD : molecularConnectivity.getFixedNeighbors()) {
237-
stringBuilder = new StringBuilder();
238-
stringBuilder.append("BOND ")
239-
.append(molecularConnectivity.getIndex())
240-
.append(" ")
241-
.append(bondedIndexInPyLSD)
242-
.append(buildShiftsComment(molecularConnectivityMap, molecularConnectivity,
243-
casekit.nmr.elucidation.Utilities.findMolecularConnectivityByIndex(
244-
molecularConnectivityMap, "H", true,
245-
bondedIndexInPyLSD)))
246-
.append("\n");
247-
if (!stringList.contains(stringBuilder.toString())) {
248-
stringList.add(stringBuilder.toString());
238+
if (!addedBONDPairs.containsKey(molecularConnectivity.getIndex())
239+
|| (addedBONDPairs.containsKey(molecularConnectivity.getIndex())
240+
&& !addedBONDPairs.get(molecularConnectivity.getIndex())
241+
.contains(bondedIndexInPyLSD))) {
242+
stringBuilder = new StringBuilder();
243+
stringBuilder.append("BOND ")
244+
.append(molecularConnectivity.getIndex())
245+
.append(" ")
246+
.append(bondedIndexInPyLSD)
247+
.append(buildShiftsComment(molecularConnectivityMap, molecularConnectivity,
248+
casekit.nmr.elucidation.Utilities.findMolecularConnectivityByIndex(
249+
molecularConnectivityMap, "H", true,
250+
bondedIndexInPyLSD)))
251+
.append("\n");
252+
if (!stringList.contains(stringBuilder.toString())) {
253+
stringList.add(stringBuilder.toString());
254+
}
255+
addedBONDPairs.putIfAbsent(molecularConnectivity.getIndex(), new HashSet<>());
256+
addedBONDPairs.get(molecularConnectivity.getIndex())
257+
.add(bondedIndexInPyLSD);
258+
addedBONDPairs.putIfAbsent(bondedIndexInPyLSD, new HashSet<>());
259+
addedBONDPairs.get(bondedIndexInPyLSD)
260+
.add(molecularConnectivity.getIndex());
249261
}
250262
}
251263
}

0 commit comments

Comments
 (0)