Open lgsmith opened 5 days ago
It may be helpful to take your mask and your structure and just seeing what this command gives you pytraj.distance(reference_trajectory, mask_string, image=True)
.
I recommend trying the suggestion given above. Also, could you share your input files? The tutorial masks are written with the expectation that each dummy atom has the same atom name (DUM
) but a different residue name (DM1
, DM2
, DM3
). Maybe your structure has the atom names and the residue names flipped?
Coincidentally, I have also written a notebook based on tutorial-8 that calculates ABFEs on BRD4. Maybe you can take a look and compare my code and structures to yours? If any of the structures or code is useful to you, please make use of it https://github.com/jaketanderson/PL-ABFE-BRD4
Thank you both for your responses. Yes, this is how this code reports a bad selection string, which uncovered an upstream problem with my notebook. For posterity, one can't have topology.to_openmm(ensure_unique_atom_names=True)
for producing an openMM topology for an instance of Modeller if one is using openff for ligand parameters but wants to have a protein in the system. Maybe the openmm force field will know what to do with the protein atoms, or maybe it won't--it doesn't emit any errors--but if you're trying to find particular atoms on particular residues, say with the mask @CA
, they'll return the empty array, which has zero dimension and therefore produces the traceback I got.
I would have really benefited from some better error handling here. Would you guys appreciate it if I added a try except clause in a few spots across restraints.py
to catch these types of issues? If yes, do you have a sense for what you'd think a good intervention should be? A minimal solution could look something like this:
try:
target = pytraj.distance(reference_trajectory, mask_string, image=True)[0]
except IndexError as e:
print(mask_string,
'seems to have found an unexpected number of atoms (possibly zero). Validate these atom masks',
*restraint_mask_list)
raise e
@jaketanderson Thanks for the alternative notebook. I'll definitely look through it.
@lgsmith adding better checking here would be a good idea. Maybe something like this three-line implementation would do the job?
# Target value
rest_type = "distance"
mask_string = " ".join(restraint_mask_list)
if len(restraint_mask_list) != pytraj.select(restraint_mask_list, reference_trajectory):
logger.error(f"There are {len(restraint_mask_list)} masks specified, but {pytraj.select(restraint_mask_list, reference_trajectory)} atoms match these masks.")
raise IndexError("The number of selection masks doesn't match the number of atoms selected.")
if len(restraint_mask_list) == 2:
# Distance restraint
I've been trying to modify tutorial-08 to do a free energy ligand binding calculation on Bromodomain-BRD4, very similar to the one in the APR paper from 2017. With my setup, Tutorial-08 will run to completion. When I swap in my own input files and change the box dimensions and offset of the dummy atoms, and the atom masks that need changing in the static restraint cell, I get an error upon trying to build the first static restraint. I am copying my traceback here, but am happy to provide whatever other information is needed. This is a clean conda env I built yesterday to contain openmmforcefields, openff-nagl, openff-toolkit, and paprika.
The first restraint call is to make a restraint between host atom 1 and dummy atom 1, so it's giving a restraint mask list of length 2 to the
static_DAT_restraint
constructor. The first part of the cell looks like this:And here's the traceback:
As you can see this probably means there's something wrong with the inputs to the pytraj distance calculation. This could be down to my masks being broken, although I am not sure how they would be. To me it looks like it thinks it's going to be operating on an array of frames, but of course per the tutorial there is just a single frame (when I visualize the
aligned_solvated_dummy_structure.pdb
in thecompdir
it looks like I would expect). Any troubleshooting ideas would be much appreciated.