Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'NoneType' object has no attribute 'select_atoms' #31

Open
silviamenin opened this issue Jan 22, 2025 · 5 comments
Open

Comments

@silviamenin
Copy link

Hi,
I am currently testing a3fe using the example_run_dir provided. I am running the calculations on a local workstation without SLURM installed. I managed to configure this by setting slurm=False in the SystemPreparationConfig. Below is the script I used to run the calculation.

import a3fe as a3
cfg = a3.SystemPreparationConfig(slurm=False)
calc = a3.Calculation(ensemble_size = 5)
calc.setup(bound_leg_sysprep_config = cfg, free_leg_sysprep_config = cfg)
calc.get_optimal_lam_vals()
calc.run(adaptive=True, runtime_constant = 0.0005)
calc.wait()
calc.analyse()
calc.save()

However, during the setup phase (calc.setup()), I encountered an AttributeError. The error seems related to the restraint selection step, where it tries to use u.select_atoms but fails because u is None. This seems to stem from the trajectory file not being loaded correctly.

Here is the full traceback of the error:

INFO - 2025-01-21 15:07:28,762 - Leg (type = BOUND)_1 - Selecting restraints for run 1...
/home/smenin/anaconda3/envs/a3fe/lib/python3.12/site-packages/BioSimSpace/Sandpit/Exscientia/FreeEnergy/_restraint_search.py:595: UserWarning: The trajectory for restraint selection has less than 50 frames (0 frames). This may result in poor restraint selection with excessively high force constants. Consider running a longer simulation or saving more frames.
  _warnings.warn(
/home/smenin/anaconda3/envs/a3fe/lib/python3.12/site-packages/BioSimSpace/Sandpit/Exscientia/Trajectory/_trajectory.py:642: UserWarning: MDAnalysis failed to read: traj=/MD2/smenin/a3fe_test/example_run_dir/bound/ensemble_equilibration_1/gromacs.xtc, top=/MD2/smenin/a3fe_test/example_run_dir/input/bound_preequil.prm7
  _warnings.warn(
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /MD2/smenin/a3fe_test/example_run_dir/../a3fe_run.py:6 in <module>                               │
│                                                                                                  │
│    3 calc = a3.Calculation(ensemble_size = 5)                                                    │
│    4 calc.save()                                                                                 │
│    5 print('\n\n\nCALC.SETUP')                                                                   │
│ ❱  6 calc.setup(bound_leg_sysprep_config = cfg, free_leg_sysprep_config = cfg)                   │
│    7 calc.get_optimal_lam_vals()                                                                 │
│    8 calc.run(adaptive=True, runtime_constant = 0.0005)                                          │
│    9 calc.wait()                                                                                 │
│                                                                                                  │
│ /home/smenin/anaconda3/envs/a3fe/lib/python3.12/site-packages/a3fe/run/calculation.py:211 in     │
│ setup                                                                                            │
│                                                                                                  │
│   208 │   │   │   │   stream_log_level=self.stream_log_level,                                    │
│   209 │   │   │   )                                                                              │
│   210 │   │   │   self.legs.append(leg)                                                          │
│ ❱ 211 │   │   │   leg.setup(configs[leg_type])                                                   │
│   212 │   │                                                                                      │
│   213 │   │   # Save the state                                                                   │
│   214 │   │   self.setup_complete = True                                                         │
│                                                                                                  │
│ /home/smenin/anaconda3/envs/a3fe/lib/python3.12/site-packages/a3fe/run/leg.py:239 in setup       │
│                                                                                                  │
│    236 │   │   │   # Run separate equilibration simulations for each of the repeats and          │
│    237 │   │   │   # extract the final structures to give a diverse ensemble of starting         │
│    238 │   │   │   # conformations. For the bound leg, this also extracts the restraints.        │
│ ❱  239 │   │   │   system = self.run_ensemble_equilibration(sysprep_config=cfg)                  │
│    240 │   │                                                                                     │
│    241 │   │   # Write input files                                                               │
│    242 │   │   self.write_input_files(system, config=cfg)                                        │
│                                                                                                  │
│ /home/smenin/anaconda3/envs/a3fe/lib/python3.12/site-packages/a3fe/run/leg.py:680 in             │
│ run_ensemble_equilibration                                                                       │
│                                                                                                  │
│    677 │   │   │   │   │   system=pre_equilibrated_system,                                       │
│    678 │   │   │   │   )                                                                         │
│    679 │   │   │   │   self._logger.info(f"Selecting restraints for run {i + 1}...")             │
│ ❱  680 │   │   │   │   restraint = _BSS.FreeEnergy.RestraintSearch.analyse(                      │
│    681 │   │   │   │   │   method="BSS",                                                         │
│    682 │   │   │   │   │   system=pre_equilibrated_system,                                       │
│    683 │   │   │   │   │   traj=traj,                                                            │
│                                                                                                  │
│ /home/smenin/anaconda3/envs/a3fe/lib/python3.12/site-packages/BioSimSpace/Sandpit/Exscientia/Fre │
│ eEnergy/_restraint_search.py:696 in analyse                                                      │
│                                                                                                  │
│    693 │   │   │   ligand_selection_str += append_to_ligand_selection                            │
│    694 │   │                                                                                     │
│    695 │   │   if restraint_type.lower() == "boresch":                                           │
│ ❱  696 │   │   │   return RestraintSearch._boresch_restraint(                                    │
│    697 │   │   │   │   u,                                                                        │
│    698 │   │   │   │   system,                                                                   │
│    699 │   │   │   │   temperature,                                                              │
│                                                                                                  │
│ /home/smenin/anaconda3/envs/a3fe/lib/python3.12/site-packages/BioSimSpace/Sandpit/Exscientia/Fre │
│ eEnergy/_restraint_search.py:817 in _boresch_restraint                                           │
│                                                                                                  │
│    814 │   │   │   │   )                                                                         │
│    815 │   │                                                                                     │
│    816 │   │   elif method == "BSS":                                                             │
│ ❱  817 │   │   │   return RestraintSearch._boresch_restraint_BSS(                                │
│    818 │   │   │   │   u,                                                                        │
│    819 │   │   │   │   system,                                                                   │
│    820 │   │   │   │   temperature,                                                              │
│                                                                                                  │
│ /home/smenin/anaconda3/envs/a3fe/lib/python3.12/site-packages/BioSimSpace/Sandpit/Exscientia/Fre │
│ eEnergy/_restraint_search.py:1773 in _boresch_restraint_BSS                                      │
│                                                                                                  │
│   1770 │   │   │   return restraint                                                              │
│   1771 │   │                                                                                     │
│   1772 │   │   # Find pairs with lowest SD                                                       │
│ ❱ 1773 │   │   pairs_ordered_sd = RestraintSearch._findOrderedPairs(                             │
│   1774 │   │   │   u, ligand_selection_str, receptor_selection_str, cutoff                       │
│   1775 │   │   )                                                                                 │
│   1776                                                                                           │
│                                                                                                  │
│ /home/smenin/anaconda3/envs/a3fe/lib/python3.12/site-packages/BioSimSpace/Sandpit/Exscientia/Fre │
│ eEnergy/_restraint_search.py:1034 in _findOrderedPairs                                           │
│                                                                                                  │
│   1031 │   │   │   the trajectory.                                                               │
│   1032 │   │   """                                                                               │
│   1033 │   │                                                                                     │
│ ❱ 1034 │   │   lig_selection = u.select_atoms(ligand_selection_str)                              │
│   1035 │   │                                                                                     │
│   1036 │   │   # Ensure that there are no shared atoms between the ligand selection and all pos  │
│   1037 │   │   all_possible_receptor_selection = u.select_atoms(receptor_selection_str)          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'NoneType' object has no attribute 'select_atoms'

Any help with this would be appreciated.
Thank you for your availability,
Silvia

@fjclark
Copy link
Collaborator

fjclark commented Jan 23, 2025

Hi,

Unfortunately SLURM is required to run all of the production MD (even though you can avoid it for the setup, as you've found). These instructions might help set it up on your workstation - let us know if there are any issues and we can help out!

The error is likely due to your MDAnalysis version being too old compared to your GROMACS version (see this issue). Could you update to the latest version of MDAnalysis and try again please? For example, MDAnalysis 2.9.0 is required if you're using GROMACS 2024.4 (see here). No need to rerun the whole thing - it might be cleanest to delete Calculation.log and Calculation.pkl, then rerun the script, and it should pick up where it left off.

Please let me know if that works and I'll enforce the most recent version of MDAnalysis in the environment yaml file to stop this happening again. Thanks!

@silviamenin
Copy link
Author

Thank you for your support.
I installed slurm locally, installed MDA version 2.9.0-dev and then I restarted the calculation.
However, while reading the error, I tried opening top and traj with vmd:

  _warnings.warn(
/home/smenin/anaconda3/envs/a3fe/lib/python3.12/site-packages/BioSimSpace/Sandpit/Exscientia/Trajectory/_trajectory.py:642: UserWarning: MDAnalysis failed to read: 
traj=/MD2/smenin/a3fe_test/example_run_dir/bound/ensemble_equilibration_1/gromacs.xtc, 
top=/MD2/smenin/a3fe_test/example_run_dir/input/bound_preequil.prm7

Here is the output:

vmd > Info) Using plugin parm7 for structure file /MD2/smenin/a3fe_test/example_run_dir/input/bound_preequil.prm7
Info) Analyzing structure ...
Info)    Atoms: 41381
Info)    Bonds: 41368
Info)    Angles: 0  Dihedrals: 0  Impropers: 0  Cross-terms: 0
Info)    Bondtypes: 0  Angletypes: 0  Dihedraltypes: 0  Impropertypes: 0
Info)    Residues: 12452
Info)    Waters: 12033
Info)    Segments: 1
Info)    Fragments: 12113   Protein: 3   Nucleic: 0
ERROR) BaseMolecule: attempt to init atoms while structure building in progress!
ERROR) Invalid number of atoms in file: 86660
Info) Using plugin xtc for coordinates from file /MD2/smenin/a3fe_test/example_run_dir/bound/ensemble_equilibration_1/gromacs.xtc
ERROR) Incorrect number of atoms (86660) in
ERROR) coordinate file /MD2/smenin/a3fe_test/example_run_dir/bound/ensemble_equilibration_1/gromacs.xtc
ERROR) Mismatch between existing molecule or structure file atom count and coordinate or trajectory file atom count.
Info) Finished with coordinate file /MD2/smenin/a3fe_test/example_run_dir/bound/ensemble_equilibration_1/gromacs.xtc.

I don't know why this is happening.
If this could be helpful, the version of gromacs I installed is 2022.6.
Thank you for your availability and have a great weekend!
Silvia

@fjclark
Copy link
Collaborator

fjclark commented Jan 24, 2025

No problem - sorry this still isn't working, and thanks for the details.

I'll try and reproduce this locally with your exact script (just to be sure that the slurm=False option isn't to blame, although this seems unlikely).

Could you please post the Leg.log file from inside /MD2/smenin/a3fe_test/example_run_dir/bound?

Thanks, you too!
Finlay

@fjclark
Copy link
Collaborator

fjclark commented Jan 24, 2025

Ah, just realised that the incorrect number of atoms in the xtc file matches that in the provided data/example_run_dir/bound/ensemble_equilibration_1/gromacs.xtc file, so I'm assuming you copied over the entire example_run_dir directory? If so, please delete everything except the input directory and try running your script again. Thanks!

@silviamenin
Copy link
Author

I'm trying again right now, thanks!
I'll let you know how it goes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants