Skip to content

Commit 6f4dbdb

Browse files
committed
:1@C4 means 1st C4 atom in the host (I think)
1 parent daf78e9 commit 6f4dbdb

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

modules/algorithms/src/main/java/ffx/algorithms/commands/test/FindRestraints.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -625,27 +625,34 @@ private Integer resolveHostAnchorMask(Molecule host, String mask) {
625625
}
626626
String[] parts = trimmed.split("@", 2);
627627
if (parts.length != 2) {
628-
logger.severe(format("Invalid mask '%s' (expected :res@atom).", mask));
628+
logger.severe(format("Invalid mask '%s' (expected :N@atom for Nth occurrence).", mask));
629629
return null;
630630
}
631-
String resPart = parts[0].trim();
631+
String occurrencePart = parts[0].trim();
632632
String atomPart = parts[1].trim();
633-
int resNum;
633+
int occurrence;
634634
try {
635-
resNum = Integer.parseInt(resPart.replaceAll("[^0-9-]", ""));
635+
occurrence = Integer.parseInt(occurrencePart.replaceAll("[^0-9-]", ""));
636636
} catch (NumberFormatException e) {
637-
logger.severe(format("Invalid residue number in mask '%s'.", mask));
637+
logger.severe(format("Invalid occurrence number in mask '%s'.", mask));
638638
return null;
639639
}
640640

641+
// Find the Nth occurrence of the atom name
642+
int count = 0;
641643
for (Atom atom : host.getAtomList()) {
642-
if (atom.getResidueNumber() == resNum && atom.getName().equalsIgnoreCase(atomPart)) {
643-
logger.info(format("Resolved %s -> host atom index %d", mask, atom.getIndex()));
644-
return atom.getIndex();
644+
if (atom.getName().equalsIgnoreCase(atomPart)) {
645+
count++;
646+
if (count == occurrence) {
647+
logger.info(format("Resolved %s -> host atom index %d (residue %d)",
648+
mask, atom.getIndex(), atom.getResidueNumber()));
649+
return atom.getIndex();
650+
}
645651
}
646652
}
647653

648-
logger.severe(format("Mask '%s' did not match any host atom.", mask));
654+
logger.severe(format("Mask '%s' did not match any host atom (found %d atoms named %s).",
655+
mask, count, atomPart));
649656
return null;
650657
}
651658

0 commit comments

Comments
 (0)