Skip to content

Commit

Permalink
Version 0.2.0 with some quality of life improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaplaza committed Jul 9, 2024
1 parent cbc6187 commit f8d946e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
26 changes: 25 additions & 1 deletion navicat_marc/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import argparse
import glob
import re
import sys
from itertools import cycle

import networkx as nx
Expand Down Expand Up @@ -102,13 +103,16 @@ def molecules_from_file(filename, scale_factor=1.10, noh=True):


def processargs(arguments):
input_list = sys.argv
input_str = " ".join(input_list)
version_str = "0.2.0"
mbuilder = argparse.ArgumentParser(
prog="navicat_marc",
description="Analyse conformer ensembles to find the most representative structures.",
epilog="Remember to cite the marc paper or repository - \n if they have a DOI by now\n - and enjoy!",
)
mbuilder.add_argument(
"-version", "--version", action="version", version="%(prog)s 0.1.10"
"-version", "--version", action="version", version=f"%(prog)s {version_str}"
)
mbuilder.add_argument(
"-i",
Expand Down Expand Up @@ -210,6 +214,15 @@ def processargs(arguments):
default=False,
help="If set, will attempt to sort molecular geometries within isomorphisms in every pairwise comparison. This is extremely time consuming in large molecules. (default: False, True if molecule is small)",
)
mbuilder.add_argument(
"-o",
"-output",
"--o",
"--output",
dest="output_filename",
default=None,
help="If set to a filename, filename of the output file that will log marc's standard output. (default: None)",
)
mbuilder.add_argument(
"-efile",
"--efile",
Expand Down Expand Up @@ -238,6 +251,17 @@ def processargs(arguments):
)
args = mbuilder.parse_args(arguments)

if args.output_filename is not None:
if not isinstance(args.output_filename, str) or re.search(
r"[^A-Za-z0-9_\-\\]", args.output_filename
):
raise InputError(
f"The provided output filename {args.output_filename} is invalid!"
)
orig_stdout = sys.stdout
ofile = open(args.output_filename, "w")
sys.stdout = ofile
print(f"Executing marc version {version_str} with input arguments:\n{input_str}")
input_list = [item for sublist in args.input for item in sublist]
if args.verb > 2:
print(f"Input files are {input_list}.")
Expand Down
25 changes: 14 additions & 11 deletions navicat_marc/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,17 +709,20 @@ def set_graph(self):
def write(self, rootname="output"):
filename = f"{rootname}.xyz"
f = open(filename, "w+")
print(f"{len(self.atoms_with_h)}", file=f)
if self.energy is not None:
printable_energy = np.round(self.energy * kcalmol_to_ha, decimals=6)
print(f"{printable_energy}", file=f)
else:
print(f"{self.title}", file=f)
for i, atom in enumerate(self.atoms_with_h):
print(
f"{number_to_symbol[atom]:2} {np.round(self.coordinates_with_h[i][0],decimals=6): } {np.round(self.coordinates_with_h[i][1],decimals=6): } {np.round(self.coordinates_with_h[i][2],decimals=6): }",
file=f,
)
with np.printoptions(
suppress=True, precision=6, formatter={"float_kind": "{:0.6f}".format}
):
print(f"{len(self.atoms_with_h)}", file=f)
if self.energy is not None:
printable_energy = np.round(self.energy * kcalmol_to_ha, decimals=6)
print(f"{printable_energy}", file=f)
else:
print(f"{self.title}", file=f)
for i, atom in enumerate(self.atoms_with_h):
print(
f"{number_to_symbol[atom]:2} {np.round(self.coordinates_with_h[i][0],decimals=6): } {np.round(self.coordinates_with_h[i][1],decimals=6): } {np.round(self.coordinates_with_h[i][2],decimals=6): }",
file=f,
)
f.close()

def update(self, atoms, coordinates):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "navicat_marc"
version = "0.1.10"
version = "0.2.0"
authors = [
{ name="R. Laplaza", email="[email protected]" },
]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
setup(
name="marc",
packages=["navicat_marc"],
version="0.1.10",
version="0.2.0",
description="Modular Analysis of Representative Conformers",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit f8d946e

Please sign in to comment.