Giter Club home page Giter Club logo

Comments (5)

jewettaij avatar jewettaij commented on July 26, 2024

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.

jewettaij avatar jewettaij commented on July 26, 2024

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.

jewettaij avatar jewettaij commented on July 26, 2024

May I close this issue?
(Thanks for the PR, by the way.)

from moltemplate.

sgsaenger avatar sgsaenger commented on July 26, 2024

Yes, please go ahead!

from moltemplate.

jewettaij avatar jewettaij commented on July 26, 2024

glad to finally get this implemented. thanks again.

from moltemplate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.