ISISNeutronMuon / MDANSE

MDANSE: Molecular Dynamics Analysis for Neutron Scattering Experiments
https://www.isis.stfc.ac.uk/Pages/MDANSEproject.aspx
GNU General Public License v3.0
21 stars 5 forks source link

MDANSE python script generation fixes and updates. #280

Closed ChiCheng45 closed 9 months ago

ChiCheng45 commented 9 months ago

Description of work Fixed and improved the MDANSE python script generation. The generated script format has been improved and the label keyword is now added as a comment to help the user. Added default labels some classes. Added unit tests to test if the script generation fails or not. Removed the references to the MDANSE-Examples files.

#!C:\Users\xcb63893\AppData\Local\anaconda3\envs\MDANSE\python.exe

########################################################
# This is an automatically generated MDANSE run script #
########################################################

from MDANSE.Framework.Jobs.IJob import IJob

########################################################
# Job parameters                                       #
########################################################

parameters = {
    'configuration_file': 'INPUT_FILENAME.lammps',      # An optional structure/configuration file
    'n_steps': 0,                                       # number of time steps (0 for automatic detection)
    'output_file': ('OUTPUT_FILENAME', 'MDTFormat'),    # MDANSE trajectory (filename, format)
    'time_step': 1.0,                                   # time step (fs)
    'time_unit': 'fs',                                  # time step unit
    'trajectory_file': 'INPUT_FILENAME.lammps',         # Any MD trajectory file
}

########################################################
# Setup and run the analysis                           #
########################################################

if __name__ == "__main__":
    ase = IJob.create('ASE')
    ase.run(parameters, status=True)

MDANSE script generation updated to give user hints on incorrect job name e.g.

(MDANSE) PS C:\Users\xcb63893\PycharmProjects\MDANSE\sandbox> mdanse.exe --js lammmmps
Traceback (most recent call last):                                               
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\xcb63893\AppData\Local\anaconda3\envs\MDANSE\Scripts\mdanse.exe\__main__.py", line 7, in <module>
  File "C:\Users\xcb63893\PycharmProjects\MDANSE\MDANSE\Src\MDANSE\Scripts\mdanse.py", line 457, in main
    options, _ = parser.parse_args()
                 ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xcb63893\AppData\Local\anaconda3\envs\MDANSE\Lib\optparse.py", line 1387, in parse_args
    stop = self._process_args(largs, rargs, values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xcb63893\AppData\Local\anaconda3\envs\MDANSE\Lib\optparse.py", line 1427, in _process_args
    self._process_long_opt(rargs, values)
  File "C:\Users\xcb63893\AppData\Local\anaconda3\envs\MDANSE\Lib\optparse.py", line 1501, in _process_long_opt
    option.process(opt, value, values, self)
  File "C:\Users\xcb63893\AppData\Local\anaconda3\envs\MDANSE\Lib\optparse.py", line 784, in process
    return self.take_action(
           ^^^^^^^^^^^^^^^^^
  File "C:\Users\xcb63893\AppData\Local\anaconda3\envs\MDANSE\Lib\optparse.py", line 805, in take_action
    self.callback(self, opt, value, parser, *args, **kwargs)
  File "C:\Users\xcb63893\PycharmProjects\MDANSE\MDANSE\Src\MDANSE\Scripts\mdanse.py", line 336, in save_job
    jobs.create(name).save(filename)
    ^^^^^^^^^^^^^^^^^
  File "C:\Users\xcb63893\PycharmProjects\MDANSE\MDANSE\Src\MDANSE\Core\SubclassFactory.py", line 171, in create
    raise ValueError(
ValueError: Could not find lammmmps in IJob. Did you mean: lammps?

Fixes Fixed crash on job script generation.

To test Test the script generation and run the unit tests.