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

MDANSE python script generation fixes and updates. #280

Merged
merged 9 commits into from
Jan 22, 2024

Conversation

ChiCheng45
Copy link
Collaborator

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.

Copy link
Collaborator

@MBartkowiakSTFC MBartkowiakSTFC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have run the tests, and also manually generated several scripts. No problems so far; the scripts generated using mdanse --js JobName command executed correctly.

Thank you for the changes!

@MBartkowiakSTFC MBartkowiakSTFC merged commit 211370b into protos Jan 22, 2024
54 checks passed
@MBartkowiakSTFC MBartkowiakSTFC deleted the chi/mdanse-script-update branch January 22, 2024 13:57
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

Successfully merging this pull request may close these issues.

2 participants