Skip to content

Commit

Permalink
Merge pull request #18 from molssi-seamm/system2
Browse files Browse the repository at this point in the history
Updated to be compatible with the new system classes.
  • Loading branch information
paulsaxe authored Feb 4, 2021
2 parents e5a4d3a + 6446df0 commit 45eb4df
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 101 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/BranchCI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches-ignore:
- 'main'
- 'master'

jobs:
light-ci:
Expand Down Expand Up @@ -51,10 +50,4 @@ jobs:
file: ./coverage.xml
flags: unittests
name: codecov-ubuntu-latest-py3.8
- name: Build documentation
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash -l {0}
run: |
docs/buildDocs.sh

19 changes: 4 additions & 15 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
name: CI

on:
# GitHub has started calling new repo's first branch "main" https://github.com/github/renaming
# Existing codes likely still have "master" as the primary branch
# Both are tracked here to keep legacy and new codes working
push:
branches:
- "master"
- "main"
pull_request:
branches:
- "master"
- "main"
schedule:
# Run on master by default Sunday morning at 3:30:
# Run by default Sunday morning at 3:30:
# Scheduled workflows run on the latest commit on the default or base branch.
# (from https://help.github.com/en/actions/reference/events-that-trigger-workflows#scheduled-events-schedule)
- cron: "30 3 * * 0"

jobs:
lint-docs:
name: Lint-Docs ubuntu-latest Py3.8
lint:
name: Lint ubuntu-latest Py3.8
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
Expand Down Expand Up @@ -53,17 +48,11 @@ jobs:
run: |
flake8 packmol_step tests
yapf --diff --recursive packmol_step tests
- name: Build documentation
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash -l {0}
run: |
docs/buildDocs.sh
test:
name: Test ${{ matrix.os }} Py${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
needs: lint-docs
needs: lint
strategy:
matrix:
os: [macOS-latest, ubuntu-latest]
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/Docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Documentation

on: push

jobs:
docs:
name: Docs ubuntu-latest Py3.8
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
# This gets all branches (1 = only current branch)
fetch-depth: 0
- name: Additional info about the build
shell: bash
run: |
uname -a
df -h
ulimit -a
# More info on options: https://github.com/conda-incubator/setup-miniconda
- uses: conda-incubator/setup-miniconda@v2
with:
python-version: 3.8
environment-file: devtools/conda-envs/test_env.yaml
activate-environment: test
auto-update-conda: false
auto-activate-base: false
show-channel-urls: true
- name: Install package
# conda setup requires this special shell
shell: bash -l {0}
run: |
python -m pip install . --no-deps
conda list
- name: Build documentation
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash -l {0}
run: |
docs/buildDocs.sh
18 changes: 4 additions & 14 deletions .github/workflows/Release.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
name: Release

on:
# GitHub has started calling new repo's first branch "main" https://github.com/github/renaming
# Existing codes likely still have "master" as the primary branch
# Both are tracked here to keep legacy and new codes working
release:
types: [published]
branches:
- "master"
- "main"

jobs:
lint-docs:
name: Lint-Docs ubuntu-latest Py3.8
lint:
name: Lint ubuntu-latest Py3.8
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
Expand Down Expand Up @@ -45,17 +41,11 @@ jobs:
run: |
flake8 packmol_step tests
yapf --diff --recursive packmol_step tests
- name: Build documentation
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash -l {0}
run: |
docs/buildDocs.sh
test:
name: Test ${{ matrix.os }} Py${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
needs: lint-docs
needs: lint
strategy:
matrix:
os: [macOS-latest, ubuntu-latest]
Expand Down Expand Up @@ -98,7 +88,7 @@ jobs:
# only to test.pypi, otherwise to both it and the main pypi.
if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest
needs: [lint-docs, test]
needs: [lint, test]
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.8
Expand Down
14 changes: 9 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
packmol step
============

.. image:: https://img.shields.io/travis/molssi-seamm/packmol_step.svg
:target: https://travis-ci.org/molssi-seamm/packmol_step
.. image:: https://img.shields.io/github/issues-pr-raw/molssi-seamm/packmol_step
:target: https://github.com/molssi-seamm/packmol_step/pulls
:alt: GitHub pull requests

.. image:: https://github.com/molssi-seamm/packmol_step/workflows/CI/badge.svg
:target: https://github.com/molssi-seamm/packmol_step/actions
:alt: Build Status

.. image:: https://codecov.io/gh/molssi-seamm/packmol_step/branch/master/graph/badge.svg
Expand All @@ -14,8 +18,8 @@ packmol step
:target: https://lgtm.com/projects/g/molssi-seamm/packmol_step/context:python
:alt: Code Quality

.. image:: https://readthedocs.org/projects/packmol-step/badge/?version=latest
:target: https://packmol-step.readthedocs.io/en/latest/?badge=latest
.. image:: https://github.com/molssi-seamm/packmol_step/workflows/Documentation/badge.svg
:target: https://molssi-seamm.github.io/packmol_step/index.html
:alt: Documentation Status

.. image:: https://pyup.io/repos/github/molssi-seamm/packmol_step/shield.svg
Expand All @@ -30,7 +34,7 @@ A step for a SEAMM flowchart for building periodic fluid boxes using Packmol


* Free software: BSD license
* Documentation: https://packmol-step.readthedocs.io.
* Documentation: https://molssi-seamm.github.io/packmol_step/index.html


Features
Expand Down
84 changes: 37 additions & 47 deletions packmol_step/packmol.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def run(self):
next_node = super().run(printer)

# Get the system
systems = self.get_variable('_systems')
system = self.get_variable('_system')
system_db = self.get_variable('_system_db')
configuration = system_db.system.configuration

# The options from command line, config file ...
path = self.options['packmol_path']
Expand Down Expand Up @@ -193,7 +193,7 @@ def run(self):
)

tmp = self.calculate(
system,
configuration,
size=size,
volume=volume,
density=density,
Expand All @@ -217,7 +217,7 @@ def run(self):
lines.append('end structure')
lines.append('')

files = {'input.pdb': system.to_pdb_text()}
files = {'input.pdb': configuration.to_pdb_text()}
files['input.inp'] = '\n'.join(lines)

self.logger.log(0, pprint.pformat(files))
Expand All @@ -239,15 +239,17 @@ def run(self):
# need to graft to the original structure.

# Create a new, temporary system and get the coordinates
tmp_sys = systems.create_system('tmp_sys', temporary=True)
tmp_sys.from_pdb_text(result['packmol.pdb']['data'])
n_atoms = tmp_sys.n_atoms()
xs = [*tmp_sys.atoms['x']]
ys = [*tmp_sys.atoms['y']]
zs = [*tmp_sys.atoms['z']]
del systems['tmp_sys']

n_atoms_per_molecule = system.n_atoms()
tmp_sys = system_db.create_system('tmp_sys', make_current=False)
tmp_configuration = tmp_sys.create_configuration('tmp')
tmp_configuration.from_pdb_text(result['packmol.pdb']['data'])
tmp_atoms = tmp_configuration.atoms
n_atoms = tmp_atoms.n_atoms
xs = [*tmp_atoms['x']]
ys = [*tmp_atoms['y']]
zs = [*tmp_atoms['z']]
system_db.delete_system(tmp_sys)

n_atoms_per_molecule = configuration.n_atoms
if n_atoms_per_molecule * n_molecules != n_atoms:
raise RuntimeError(
'Serious problem in Packmol with the number of atoms'
Expand All @@ -256,47 +258,35 @@ def run(self):
)
)

# get the initial atoms so that we can duplicate them
rows = system.atoms.atoms()
atom_data = {}
columns = [x[0] for x in rows.description]
for column in columns:
atom_data[column] = []
for row in rows:
for column, value in zip(columns, row):
atom_data[column].append(value)
atom_ids = atom_data['id']
# Get a copy of the current atom and bond data
atoms = configuration.atoms
atom_data = atoms.get_as_dict()
# index of atoms to use for bonds
index = {j: i for i, j in enumerate(atom_data['id'])}
del atom_data['id']
to_index = {j: i for i, j in enumerate(atom_ids)}

# and bonds
rows = system.bonds.bonds()
bond_data = {}
columns = [x[0] for x in rows.description]
for column in columns:
bond_data[column] = []
for row in rows:
for column, value in zip(columns, row):
bond_data[column].append(value)
i_index = [to_index[i] for i in bond_data['i']]
j_index = [to_index[j] for j in bond_data['j']]
bonds = configuration.bonds
bond_data = bonds.get_as_dict()
del bond_data['id']

i_index = [index[i] for i in bond_data['i']]
j_index = [index[j] for j in bond_data['j']]

# Append the atoms and bonds n_molecules-1 times to give n_molecules
for copy in range(1, n_molecules):
new_atoms = system.atoms.append(**atom_data)
new_atoms = configuration.atoms.append(**atom_data)

bond_data['i'] = [new_atoms[i] for i in i_index]
bond_data['j'] = [new_atoms[j] for j in j_index]
system.bonds.append(**bond_data)
configuration.bonds.append(**bond_data)

# And set the coordinates to the correct ones
system.atoms['x'] = xs
system.atoms['y'] = ys
system.atoms['z'] = zs
configuration.atoms['x'] = xs
configuration.atoms['y'] = ys
configuration.atoms['z'] = zs

# make periodic of correct size
system.periodicity = 3
system.cell.set_cell(size, size, size, 90.0, 90.0, 90.0)
configuration.periodicity = 3
configuration.cell.parameters = (size, size, size, 90.0, 90.0, 90.0)

string = 'Created a cubic cell {size:.5~P} on a side'
string += ' with {n_molecules} molecules'
Expand Down Expand Up @@ -326,7 +316,7 @@ def run(self):

def calculate(
self,
system,
configuration,
size=None,
volume=None,
density=None,
Expand All @@ -337,13 +327,13 @@ def calculate(
):
"""Work out the other variables given any two independent ones"""

if system.n_atoms() == 0:
if configuration.n_atoms == 0:
self.logger.error('Packmol calculate: there is no structure!')
raise RuntimeError('Packmol calculate: there is no structure!')

elements = system.atoms.symbols()
elements = configuration.atoms.symbols
n_atoms_per_molecule = len(elements)
molecular_mass = system.mass() * ureg.g / ureg.mol # g/mol
molecular_mass = configuration.mass * ureg.g / ureg.mol # g/mol
molecular_mass.ito('kg')

n_parameters = 0
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
seamm==2020.12.4
seamm==2021.2.2
Loading

0 comments on commit 45eb4df

Please sign in to comment.