Comments (5)
Ugh. I never imagined anybody would read that code. I'm wincing thinking about it. I only ever expected people would want to access it from the bash terminal. The "ltemplify.py" file had one enormous main() function, 4500 lines long. I wrote it in haste as just a quick and dirty way to get other people's LAMMPS simulation data into moltemplate format. I never realized how much it would be used, or how large it would grow.
Although I did not follow your exact recommendations, I took your general suggestions to clean up this code to heart. Instructions for accessing the functionality are included at the bottom of this message.
I also wrote up some documentation
It's still a appalling mess, but it's a somewhat easier to read appalling mess.
State:
There are an enormous number of variables in this code describing the (often complicated) state of the system described in the user's simulation files. Instead of using one ridiculously enormous function with a huge list of local variables (or global variables!), I a made a class. All these variables are now members of that class. Following your suggestions, I split the main() or ui() function into 7 smaller member functions of that class which do various things like parse the argument list, read the files, pass through various sections of the files, and write the final output file. I was still too lazy to think up good names for these functions, but at least I added some cursory docstrings.
To invoke ltemplify.py from within python use:
import moltemplate
# Read the command line arguments to figure out which files
# we will need to read (and also how to modify the output format).
ltemp = moltemplate.ltemplify.Ltemplify(argument_list)
# Using these settings, convert these files into a single file.
# Send the content that file to sys.stdout.
import sys
ltemp.Convert(sys.stdout)
# (To send to a string, I think you can use io.StringIO instead of sys.stdout.)
(I tested this recently, but please let me know if any of this fails to work.)
As for the argument list,
see documentation here
Perhaps one day, I will use sphinx and readthedocs. But currently, most of my documentation is still written in latex, and some of it eventually gets copied to the various .md files scattered throughout the "doc/" subdirectory.
Similarly, I will use argparse in future projects, but I was too lazy to rewrite the current arg-parser which is several hundred lines of code, and afraid of introducing more bugs if I did.
If you have no more suggestions, I will close this issue.
Thank you for your suggestions, and my condolences that you had to open this file.
from moltemplate.
Regarding this issue:
Semi-related to this (just don't want to spam issues), would it be possible to parse the atom_style comment from the Atoms section? At least, comments like in moltemplate.sh about the guessed/default atom_style should be printed.
Yes. This is implemented finally. Great suggestion.
from moltemplate.
May I close this issue?
(Thanks for the PR, by the way.)
from moltemplate.
Yes, please go ahead!
from moltemplate.
glad to finally get this implemented. thanks again.
from moltemplate.
Related Issues (20)
- The number of columns in your data file does not match the LAMMPS atom_style you selected. HOT 4
- Tests fail to run: no tests ran in 0.09 seconds HOT 7
- Error: There are no atoms in the system (with write("Data Atoms") command) HOT 4
- How to use LAMMPS' "variable" command in an .LT file HOT 6
- How to use moltemplate to construct crystals, such as SiC HOT 1
- Force field in the GROMACS topology format to LAMMPS format HOT 4
- The number of columns in your data file does not match the LAMMPS atom_style you selected. Use the -atomstyle <style> command line argument. HOT 5
- [Doc] Add direct pip installation command in README.md HOT 1
- Center atom for improper dihedral coefficients in oplsaa.it HOT 1
- Specifying Geometry in Moltemplate HOT 2
- Help for reading coordinates from pdb files. HOT 1
- running moltemplate on large systems is slow and needs a lot of memory HOT 5
- Atom type not found in the oplsaa.lt HOT 3
- Dihedrals in ethene? HOT 2
- SPC/E in force_fields/spce_oplsaa.lt HOT 4
- One test fails HOT 2
- Bug in cleanup_moltemplate.sh HOT 4
- Error in membrane example HOT 2
- How to change the force-field in an ATB file (to OLPSAA) HOT 2
- 英語版ページの「Staff Wanted」を削除する HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moltemplate.