GunnerLab / Stable-MCCE

Stable version of MCCE.
MIT License
9 stars 14 forks source link

ms_analysis.py tweak to allow for different head3.lst path #260

Closed CatChenal closed 10 months ago

CatChenal commented 10 months ago

Right now, the read_conformers function in bin/ms_analysis.py has "head3.lst" hard-coded in the open call L316:

def read_conformers():
    conformers = []
    lines = open("head3.lst").readlines()
    lines.pop(0)
    for line in lines:
        conf = Conformer()
        conf.load_from_head3lst(line)
        conformers.append(conf)

    return conformers

I propose the following non-breaking fix:

def read_conformers(head3_path):
    conformers = []
    lines = open(head3_path).readlines()
    lines.pop(0)
    for line in lines:
        conf = Conformer()
        conf.load_from_head3lst(line)
        conformers.append(conf)

    return conformers

conformers = read_conformers("head3.lst")

Outcome of the change: Users of the ms_analysis.py module can obtain the conformers list from head3.lst with a different path, yet the former behavior is unchanged. Example:

import ms_analysis as msa
from pathlib import Path

mcce_dir = Path("some/path/to/MCCE/output/")
head3 = mcce_dir.joinpath("head3.lst")

# redo conformer loading with non-standard path:
conformers = msa.read_conformers(head3)
[...]
CatChenal commented 10 months ago

Actually, above code is breaking: need a try/except block in ms_analysis.py to catch file not found.

CatChenal commented 10 months ago

Addressed by PR #261