Skip to content

Commit

Permalink
Merge pull request #44 from TheoChem-VU/main
Browse files Browse the repository at this point in the history
Merge main into 20
  • Loading branch information
ksalimans authored Oct 17, 2023
2 parents e21cd62 + eacb5b4 commit c64bae7
Show file tree
Hide file tree
Showing 29 changed files with 291 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ on:
pull_request:
types: [closed]
branches: [main]
release:
types: [published]

jobs:
build_and_deploy:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_python_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff pytest pytest-cov
pip install ruff==0.0.177 pytest pytest-cov
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install -e .
- name: Lint with ruff
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/pypi_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Publishing to PyPI

on:
release:
types: [published]
workflow_dispatch:


concurrency:
group: "publishing"
cancel-in-progress: true

jobs:
pypi-publish:
name: Upload release to PyPI
runs-on: ubuntu-latest
environment:
name: pypi-publish
url: https://pypi.org/project/${{ github.event.repository.name }}/
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Build package
run: |
python -m pip install --upgrade build
python -m build
- name: Publish ${{ github.event.repository.name }} to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true

9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
[![Documentation](https://github.com/TheoChem-VU/TCutility/actions/workflows/build_docs.yml/badge.svg)](https://github.com/TheoChem-VU/TCutility/actions/workflows/build_docs.yml) [![Testing](https://github.com/TheoChem-VU/TCutility/actions/workflows/build_python_versions.yml/badge.svg)](https://github.com/TheoChem-VU/TCutility/actions/workflows/build_python_versions.yml)
[![Documentation](https://github.com/TheoChem-VU/TCutility/actions/workflows/build_docs.yml/badge.svg)](https://github.com/TheoChem-VU/TCutility/actions/workflows/build_docs.yml) [![Testing](https://github.com/TheoChem-VU/TCutility/actions/workflows/build_python_versions.yml/badge.svg)](https://github.com/TheoChem-VU/TCutility/actions/workflows/build_python_versions.yml) [![Publishing to PyPI](https://github.com/TheoChem-VU/TCutility/actions/workflows/pypi_publish.yml/badge.svg?branch=main)](https://github.com/TheoChem-VU/TCutility/actions/workflows/pypi_publish.yml)


[![TCutility version](https://badge.fury.io/py/TCutility.svg)](https://pypi.org/project/TCutility/)

# TCutility
Utility functions/classes for the TheoCheM programs

# Installation

The easiest way is installing this python package via pip (not yet working since it is not published on PyPI):
``` python -m pip install TCutility ```
The easiest way is installing this python package via pip:
``` python -m pip install TCutility```

It is also possible to install in locally by first cloning this repository in your terminal:

Expand Down
129 changes: 129 additions & 0 deletions TCutility/molecule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
from scm import plams
from TCutility.results import result


def parse_str(s: str):
# checks if string should be an int, float, bool or string

# sanitization first
# empty s returns None
# if s is not a str return it
if s == '':
return None
if not isinstance(s, str):
return s

# to parse the string we use try/except method
try:
return int(s)
except ValueError:
pass

try:
return float(s)
except ValueError:
pass

# bool type casting always works, so we have to specifically check for correct strings
if s in ['True', 'False']:
return bool(s)

return s


def save(mol: plams.Molecule, path: str, comment: str = None):
''' Save a molecule in a custom xyz file format.
Molecule and atom flags can be provided as the "flags" parameter of the object (mol.flags and atom.flags).
'''
comment = comment or mol.comment
with open(path, 'w+') as f:
f.write(f'{len(mol.atoms)}\n{comment}\n')
for atom in mol.atoms:
flags_str = ''
flags = atom.flags if hasattr(atom, 'flags') else {}
for key, value in flags.items():
if key == 'tags':
if len(value) > 0:
flags_str += ' '.join([str(x) for x in value]) + ' '
else:
continue
else:
flags_str += f'{key}={value} '

f.write(f'{atom.symbol}\t{atom.coords[0]: .10f}\t{atom.coords[1]: .10f}\t{atom.coords[2]: .10f}\t{flags_str}\n')

f.write('\n')

flags = mol.flags if hasattr(mol, 'flags') else {}
for key, value in flags.items():
if key == 'tags':
f.write("\n".join([str(x) for x in value]) + '\n')
else:
f.write(f'{key} = {value}\n')


def load(path) -> plams.Molecule:
'''
Load a molecule from a given xyz file path.
The xyz file is structured as follows:
```
[int] number of atoms
Comment line
Xx X1 Y1 Z1 atom_tag1 atom_tag2 atom_key1=...
Xx X2 Y2 Z2 atom_tag1 atom_tag2 atom_key1=...
Xx X3 Y3 Z3
mol_tag1
mol_tag2
mol_key1=...
mol_key2 = ...
```
The xyz file is parsed and returned as a plams.Molecule object.
Flags and tags are given as mol.flags and mol.flags.tags respectively
Similarly for the atoms, the flags and tags are given as mol.atoms[i].flags and mol.atoms[i].flags.tags
'''
def parse_flags(args):
ret = result.Result()
ret.tags = []
for arg in args:
# flags are given as key=value pairs
# tags are given as loose keys
if '=' in arg:
key, value = arg.split('=')
ret[key.strip()] = parse_str(value.strip())
else:
ret.tags.append(parse_str(arg.strip()))
return ret

with open(path) as f:
lines = [line.strip() for line in f.readlines()]

mol = plams.Molecule()

natoms = int(lines[0])
mol.comment = lines[1]
# not all lines in the file will define atoms. Lines after line natoms+2 will be used for flags
atom_lines = lines[2:natoms+2]
for line in atom_lines:
# parse every atom first
symbol, x, y, z, *args = line.split()
atom = plams.Atom(symbol=symbol, coords=(float(x), float(y), float(z)))
atom.flags = parse_flags(args)
mol.add_atom(atom)

# after the atoms we parse the flags for the molecule
flag_lines = lines[natoms+2:]
flag_lines = [line.strip() for line in flag_lines if line.strip()]
mol.flags = parse_flags(flag_lines)

return mol


if __name__ == '__main__':
mol = load(r"D:\Users\Yuman\Desktop\PhD\ychem\calculations2\5ef3a511141a993d83552515df6bf882a7560dd806f88df4e2c2887b4d2a9595\transitionstate\input_mol.xyz")
print(mol)
print(mol.flags)
print(mol[1].flags)

Binary file modified docs/_build/doctrees/TCutility.constants.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/TCutility.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/TCutility.results.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/_build/doctrees/index.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/modules.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/shared/usage_results.doctree
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/_build/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 5f993dbd9f9925ccd9eda29ef8d681f1
config: 9511e45ca111478053fe65e1fb308881
tags: 645f666f9bcd5a90fca523b33c5a78b7
4 changes: 2 additions & 2 deletions docs/_build/html/TCutility.constants.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<title>TCutility.constants package &#8212; TCutility v0.1.0 documentation</title>
<title>TCutility.constants package &#8212; TCutility v0.2.1 documentation</title>



Expand All @@ -35,7 +35,7 @@
<link rel="preload" as="script" href="_static/scripts/pydata-sphinx-theme.js?digest=ac02cc09edc035673794" />
<script src="_static/vendor/fontawesome/6.1.2/js/all.min.js?digest=ac02cc09edc035673794"></script>

<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js?v=7a6ff16f"></script>
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js?v=7e7ff5c5"></script>
<script src="_static/doctools.js?v=888ff710"></script>
<script src="_static/sphinx_highlight.js?v=4825356b"></script>
<script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/_build/html/TCutility.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<title>TCutility package &#8212; TCutility v0.1.0 documentation</title>
<title>TCutility package &#8212; TCutility v0.2.1 documentation</title>



Expand All @@ -35,7 +35,7 @@
<link rel="preload" as="script" href="_static/scripts/pydata-sphinx-theme.js?digest=ac02cc09edc035673794" />
<script src="_static/vendor/fontawesome/6.1.2/js/all.min.js?digest=ac02cc09edc035673794"></script>

<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js?v=7a6ff16f"></script>
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js?v=7e7ff5c5"></script>
<script src="_static/doctools.js?v=888ff710"></script>
<script src="_static/sphinx_highlight.js?v=4825356b"></script>
<script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
Expand Down
8 changes: 4 additions & 4 deletions docs/_build/html/TCutility.results.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<title>TCutility.results package &#8212; TCutility v0.1.0 documentation</title>
<title>TCutility.results package &#8212; TCutility v0.2.1 documentation</title>



Expand All @@ -35,7 +35,7 @@
<link rel="preload" as="script" href="_static/scripts/pydata-sphinx-theme.js?digest=ac02cc09edc035673794" />
<script src="_static/vendor/fontawesome/6.1.2/js/all.min.js?digest=ac02cc09edc035673794"></script>

<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js?v=7a6ff16f"></script>
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js?v=7e7ff5c5"></script>
<script src="_static/doctools.js?v=888ff710"></script>
<script src="_static/sphinx_highlight.js?v=4825356b"></script>
<script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
Expand All @@ -44,7 +44,7 @@
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="TCutility.constants package" href="TCutility.constants.html" />
<link rel="prev" title="TCutility v0.1.0 documentation" href="index.html" />
<link rel="prev" title="TCutility v0.2.1 documentation" href="index.html" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="docsearch:language" content="en"/>
</head>
Expand Down Expand Up @@ -691,7 +691,7 @@ <h1>TCutility.results package<a class="headerlink" href="#tcutility-results-pack
<i class="fa-solid fa-angle-left"></i>
<div class="prev-next-info">
<p class="prev-next-subtitle">previous</p>
<p class="prev-next-title">TCutility v0.1.0 documentation</p>
<p class="prev-next-title">TCutility v0.2.1 documentation</p>
</div>
</a>
<a class="right-next"
Expand Down
4 changes: 2 additions & 2 deletions docs/_build/html/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Overview: module code &#8212; TCutility v0.1.0 documentation</title>
<title>Overview: module code &#8212; TCutility v0.2.1 documentation</title>



Expand All @@ -34,7 +34,7 @@
<link rel="preload" as="script" href="../_static/scripts/pydata-sphinx-theme.js?digest=ac02cc09edc035673794" />
<script src="../_static/vendor/fontawesome/6.1.2/js/all.min.js?digest=ac02cc09edc035673794"></script>

<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js?v=7a6ff16f"></script>
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js?v=7e7ff5c5"></script>
<script src="../_static/doctools.js?v=888ff710"></script>
<script src="../_static/sphinx_highlight.js?v=4825356b"></script>
<script>DOCUMENTATION_OPTIONS.pagename = '_modules/index';</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/_build/html/_static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
VERSION: 'v0.1.0',
VERSION: 'v0.2.1',
LANGUAGE: 'en',
COLLAPSE_INDEX: false,
BUILDER: 'html',
Expand Down
4 changes: 2 additions & 2 deletions docs/_build/html/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Index &#8212; TCutility v0.1.0 documentation</title>
<title>Index &#8212; TCutility v0.2.1 documentation</title>



Expand All @@ -34,7 +34,7 @@
<link rel="preload" as="script" href="_static/scripts/pydata-sphinx-theme.js?digest=ac02cc09edc035673794" />
<script src="_static/vendor/fontawesome/6.1.2/js/all.min.js?digest=ac02cc09edc035673794"></script>

<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js?v=7a6ff16f"></script>
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js?v=7e7ff5c5"></script>
<script src="_static/doctools.js?v=888ff710"></script>
<script src="_static/sphinx_highlight.js?v=4825356b"></script>
<script>DOCUMENTATION_OPTIONS.pagename = 'genindex';</script>
Expand Down
8 changes: 4 additions & 4 deletions docs/_build/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<title>TCutility v0.1.0 documentation &#8212; TCutility v0.1.0 documentation</title>
<title>TCutility v0.2.1 documentation &#8212; TCutility v0.2.1 documentation</title>



Expand All @@ -35,7 +35,7 @@
<link rel="preload" as="script" href="_static/scripts/pydata-sphinx-theme.js?digest=ac02cc09edc035673794" />
<script src="_static/vendor/fontawesome/6.1.2/js/all.min.js?digest=ac02cc09edc035673794"></script>

<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js?v=7a6ff16f"></script>
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js?v=7e7ff5c5"></script>
<script src="_static/doctools.js?v=888ff710"></script>
<script src="_static/sphinx_highlight.js?v=4825356b"></script>
<script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
Expand Down Expand Up @@ -219,7 +219,7 @@
<article class="bd-article" role="main">

<section id="tcutility-projectversion-documentation">
<h1>TCutility v0.1.0 documentation<a class="headerlink" href="#tcutility-projectversion-documentation" title="Permalink to this heading">#</a></h1>
<h1>TCutility v0.2.1 documentation<a class="headerlink" href="#tcutility-projectversion-documentation" title="Permalink to this heading">#</a></h1>
<p><strong>TCutility</strong> is a Python library containing many helper functions and classes for use in programs written in the TheoCheM group.</p>
<div class="toctree-wrapper compound">
<p aria-level="2" class="caption" role="heading"><span class="caption-text">Contents:</span></p>
Expand Down Expand Up @@ -284,7 +284,7 @@ <h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Pe
</div>
<nav class="bd-toc-nav page-toc">
<ul class="visible nav section-nav flex-column">
<li class="toc-h1 nav-item toc-entry"><a class="reference internal nav-link" href="#">TCutility v0.1.0 documentation</a></li>
<li class="toc-h1 nav-item toc-entry"><a class="reference internal nav-link" href="#">TCutility v0.2.1 documentation</a></li>
<li class="toc-h1 nav-item toc-entry"><a class="reference internal nav-link" href="#indices-and-tables">Indices and tables</a></li>
</ul>

Expand Down
4 changes: 2 additions & 2 deletions docs/_build/html/modules.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<title>TCutility &#8212; TCutility v0.1.0 documentation</title>
<title>TCutility &#8212; TCutility v0.2.1 documentation</title>



Expand All @@ -35,7 +35,7 @@
<link rel="preload" as="script" href="_static/scripts/pydata-sphinx-theme.js?digest=ac02cc09edc035673794" />
<script src="_static/vendor/fontawesome/6.1.2/js/all.min.js?digest=ac02cc09edc035673794"></script>

<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js?v=7a6ff16f"></script>
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js?v=7e7ff5c5"></script>
<script src="_static/doctools.js?v=888ff710"></script>
<script src="_static/sphinx_highlight.js?v=4825356b"></script>
<script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
Expand Down
Binary file modified docs/_build/html/objects.inv
Binary file not shown.
Loading

0 comments on commit c64bae7

Please sign in to comment.