patonlab / GoodVibes

Calculate quasi-harmonic free energies from Gaussian output files with temperature and other corrections
http://www.patonlab.colostate.edu
MIT License
134 stars 52 forks source link

Using GoodVibes from other Python scripts #35

Closed fdroessler closed 2 years ago

fdroessler commented 4 years ago

Hi, just wondering if there is a recommended way of importing goodvibes in other python scripts? I played around with some ideas but was wondering if there is a better way or recommended way.

If there is no such thing atm, I could try clean my idea up and submit a PR if that there is interest.

RaphaelRobidas commented 4 years ago

I would be very interested to have this too!

kjelljorner commented 3 years ago

I have some code for a wrapper if people would be interested. Could be it's own repo or part of the official one. Feel free to use this but I by no means give any guarantees 😁

from subprocess import Popen, PIPE

class GoodVibes:
    """Performs and stores results of thermochemical data with Paton's GoodVibes code.

    Args:
        filename (str): Name of Gaussian log file
        quasi_harmonic (str): Choice of method: 'grimme' (default) or 'truhlar'
        scaling (float): Scaling factor for frequencies (default: 1.0)
        standard_state (float): Standard state (M, default: 1.0)
        temperature (float): Temperature (K, default: 298.15)

    Attributes:
        enthalpy (float): Enthalpy (a.u)
        free_energy (float): Free energy (a.u.)
        free_energy_qh (float): Free energy with quasi-harmonic corrections (a.u.)
        t_entropy (float): Temperature times entropy (a.u.)
        t_entropy_qh (float): Temperature times entropy with quasi-harmonic corrections (a.u.)
    """
    def __init__(self, filename, temperature=298.15, scaling=1.0, standard_state=1.0, quasi_harmonic="grimme", cutoff=100):
        # Set up and run Goodvibes
        self.filename = filename
        submit_string = f"python -m  goodvibes --qs {quasi_harmonic} -f {cutoff} -v {scaling} -t {temperature} -c {standard_state} {filename}"
        process = Popen(submit_string.split(), stdout=PIPE)
        output = process.communicate()[0].decode()

        # Read output
        lines = output.split("\n")
        lines = [line.strip() for line in lines]
        result_line = lines[-3].split()

        self.electronic_energy = float(result_line[2])        
        self.zpe = float(result_line[3])
        self.enthalpy = float(result_line[4])
        self.t_entropy = float(result_line[5])
        self.t_entropy_qh = float(result_line[6])
        self.free_energy = float(result_line[7])
        self.free_energy_qh = float(result_line[8])       

    def __repr__(self):
        return f"{self.__class__.__name__}({self.filename!r})"
bobbypaton commented 3 years ago

Thanks for these suggestions and code @fdroessler @RaphaelRobidas @kjelljorner !

The next push, hopefully before the end of 2020, will make this a lot easier to do from another script/program. There will be some Jupyter notebook examples to illustrate how this can be done.

bobbypaton commented 2 years ago

Took a while but this is now done in branch GV4. Will be in the next pip/conda release