You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _episodes/03-multiple_files.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -225,7 +225,7 @@ where anything in the braces is a python variable and it will print the value of
225
225
226
226
## Project Assignment
227
227
228
-
This is a project assignment which you can complete to test your skills.
228
+
This is a project assignment which you can complete to test your skills. This project should be used when this material is used in a long workshop, or if you are working through this material independently.
229
229
230
230
> ## File parsing homework
231
231
> In the lesson materials, there is a file called `03_Prod.mdout`. This is a file output by the Amber molecular dynamics simulation program.
Copy file name to clipboardExpand all lines: _episodes/07-command_line.md
+105-1
Original file line number
Diff line number
Diff line change
@@ -309,6 +309,110 @@ if __name__ == "__main__":
309
309
~~~
310
310
{: .language-python}
311
311
312
-
312
+
> ## Project Assignment
313
+
>
314
+
> For this homework assignment, you will return to your Project from Lesson 3.
315
+
>
316
+
> Create a command line script using `argparse` which can take in an `mdout` file from Amber, pull out total energy for each time step, and write a new file containing these values. The script should take a file name (`03_Prod.mdout`) OR pattern (`*.mdout`) and output files with the names `filename_Etot.txt`**in the same directory as the files**. Modify your week 1 homework to do this. In contrast to week 1, truncate the last two values from your script (these are an average value and a fluctuation value) from the file you write.
317
+
>
318
+
> You can download a directory containing more mdout files [here](../data/mdout.zip)
319
+
>
320
+
> Call your script `analyze_mdout.py`. You should be able to call the script in the following > ways:
321
+
>
322
+
> ~~~
323
+
> $ python analyze_mdout.py 03_Prod.mdout
324
+
> ~~~
325
+
> {: .language-bash}
326
+
>
327
+
> or
328
+
>
329
+
> ~~~
330
+
> $ python analyze_mdout.py '*.out'
331
+
> ~~~
332
+
> {: .language-bash}
333
+
>
334
+
> When you call help, you should get the following output:
335
+
> ~~~
336
+
> $ python analyze_mdout.py --help
337
+
> ~~~
338
+
> {: .language-bash}
339
+
>
340
+
> ~~~
341
+
> usage: This script parses amber mdout files to extract the total energy. You can also use it to create plots.
342
+
> [-h] [--make_plots] path
343
+
>
344
+
> positional arguments:
345
+
> path The filepath to the file(s) to be analyzed. To analyze
346
+
> multiple files, you can use the `*` pattern.
347
+
>
348
+
> optional arguments:
349
+
> -h, --help show this help message and exit
350
+
> ~~~
351
+
> {: .output}
352
+
> **Extension**
353
+
> Add an optional argument to your script to create plots of the data with matplotlib.
354
+
>
355
+
>> ## Solution
356
+
>> ~~~
357
+
>> import os
358
+
>> import glob
359
+
>> import argparse
360
+
>> import matplotlib.pyplot as plt
361
+
>>
362
+
>>
363
+
>> if __name__ == "__main__":
364
+
>>
365
+
>> parser = argparse.ArgumentParser("This script parses amber mdout files to extract the total energy. You can also use it to create plots.")
366
+
>> parser.add_argument("path", help="The filepath to the file(s) to be analyzed. To analyze multiple files, you can use the `*` pattern.", type=str)
367
+
>> parser.add_argument("--make_plots", help="Create a line plot of the values.", action='store_true')
0 commit comments