Skip to content

Commit

Permalink
Merge pull request #5 from molssi-seamm/cleanup/description
Browse files Browse the repository at this point in the history
Cleanup/description
  • Loading branch information
paulsaxe authored Aug 27, 2019
2 parents 9bc143b + 4dd2c23 commit f05066e
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 60 deletions.
26 changes: 17 additions & 9 deletions packmol_step/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
# -*- coding: utf-8 -*-

"""Top-level package for packmol step."""

__author__ = """Paul Saxe"""
__email__ = '[email protected]'
__version__ = '0.1.0'
"""
packmol_step
A step for building fluid boxes using Packmol
"""

# Bring up the classes so that they appear to be directly in
# the packmol_step package.

from packmol_step.packmol import PACKMOL # noqa: F401
from packmol_step.packmol_parameters import PACKMOL_Parameters # noqa: F401
from packmol_step.packmol_step import PACKMOLStep # noqa: F401
from packmol_step.tk_packmol import TkPACKMOL # noqa: F401
from packmol_step.packmol import Packmol # noqa: F401
from packmol_step.packmol_parameters import PackmolParameters # noqa: F401
from packmol_step.packmol_step import PackmolStep # noqa: F401
from packmol_step.tk_packmol import TkPackmol # noqa: F401

# Handle versioneer
from ._version import get_versions
__author__ = """Paul Saxe"""
__email__ = '[email protected]'
versions = get_versions()
__version__ = versions['version']
__git_revision__ = versions['full-revisionid']
del get_versions, versions
71 changes: 39 additions & 32 deletions packmol_step/packmol.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

"""A node or step for PACKMOL in a seamm"""
"""A node or step for Packmol in a seamm"""

import logging
import mendeleev
Expand All @@ -18,24 +18,47 @@
printer = printing.getPrinter('packmol')


class PACKMOL(seamm.Node):
class Packmol(seamm.Node):

def __init__(self, flowchart=None, extension=None):
'''Setup the main PACKMOL step
'''Setup the main Packmol step
Keyword arguments:
'''
logger.debug('Creating PACKMOL {}'.format(self))
logger.debug('Creating Packmol {}'.format(self))

super().__init__(
flowchart=flowchart, title='PACKMOL', extension=extension
flowchart=flowchart, title='Packmol', extension=extension
)

self.parameters = packmol_step.PACKMOL_Parameters()
self.parameters = packmol_step.PackmolParameters()

def description(self, P):
"""Prepare information about what this node will do
@property
def version(self):
"""The semantic version of this module.
"""
return packmol_step.__version__

@property
def git_revision(self):
"""The git version of this module.
"""
return packmol_step.__git_revision__

def description_text(self, P=None):
"""Return a short description of this step.
Return a nicely formatted string describing what this step will
do.
Keyword arguments:
P: a dictionary of parameter values, which may be variables
or final values. If None, then the parameters values will
be used as is.
"""

if not P:
P = self.parameters.values_to_dict()

text = 'Creating a cubic supercell '
if P['method'][0] == '$':
Expand Down Expand Up @@ -72,26 +95,10 @@ def description(self, P):
"Don't recognize the submethod {}".format(P['submethod'])
)

return text

def describe(self, indent='', json_dict=None):
"""Write out information about what this node will do
If json_dict is passed in, add information to that dictionary
so that it can be written out by the controller as appropriate.
"""

next_node = super().describe(indent, json_dict)

P = self.parameters.values_to_dict()

text = self.description(P)

job.job(__(text, **P, indent=self.indent + ' '))

return next_node
return self.header + '\n' + __(text, **P, indent=4*' ').__str__()

def run(self):
"""Run a PACKMOL building step
"""Run a Packmol building step
"""

next_node = super().run(printer)
Expand All @@ -104,8 +111,7 @@ def run(self):
logger.info('submethod = {}'.format(P['submethod']))

# Print what we are doing
text = self.description(P)
printer.important(__(text, **P, indent=' '))
printer.important(__(self.description_text(P), indent=self.indent))

size = None
volume = None
Expand Down Expand Up @@ -197,7 +203,7 @@ def run(self):
n_atoms = len(atoms['elements'])
if n_atoms_per_molecule * n_molecules != n_atoms:
raise RuntimeError(
'Serious problem in PACKMOL with the number of atoms'
'Serious problem in Packmol with the number of atoms'
' {} != {}'.format(
n_atoms, n_atoms_per_molecule * n_molecules
)
Expand Down Expand Up @@ -237,9 +243,10 @@ def run(self):
string += ' for a total of {n_atoms} atoms in the cell'
string += ' and a density of {density:.5~P}.'
printer.important(__(string, indent=' ', **tmp))
printer.important('')

logger.log(
0, 'Structure created by PACKMOL:\n\n' +
0, 'Structure created by Packmol:\n\n' +
pprint.pformat(data.structure)
)

Expand All @@ -258,8 +265,8 @@ def calculate(
"""Work out the other variables given any two independent ones"""

if data.structure is None:
logger.error('PACKMOL run(): there is no structure!')
raise RuntimeError('PACKMOL run(): there is no structure!')
logger.error('Packmol run(): there is no structure!')
raise RuntimeError('Packmol run(): there is no structure!')

elements = data.structure['atoms']['elements']
n_atoms_per_molecule = len(elements)
Expand Down
10 changes: 5 additions & 5 deletions packmol_step/packmol_parameters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""Control parameters for PACKMOL, currently for packing fluids
"""Control parameters for Packmol, currently for packing fluids
"""

import logging
Expand All @@ -8,8 +8,8 @@
logger = logging.getLogger(__name__)


class PACKMOL_Parameters(seamm.Parameters):
"""The control parameters for PACKMOL packing fluids
class PackmolParameters(seamm.Parameters):
"""The control parameters for Packmol packing fluids
"""
methods = {
'size of cubic cell': (
Expand Down Expand Up @@ -76,7 +76,7 @@ class PACKMOL_Parameters(seamm.Parameters):
"description": "Gap around cell:",
"help_text":
(
"Since PACKMOL does not support periodic systems "
"Since Packmol does not support periodic systems "
"we will build a box with this gap around the "
"atoms, then make it periodic. The gap ensures "
"that molecules at the boundary do not hit images"
Expand Down Expand Up @@ -138,6 +138,6 @@ def __init__(self, defaults={}, data=None):
parameters given in the class"""

super().__init__(
defaults={**PACKMOL_Parameters.parameters, **defaults},
defaults={**PackmolParameters.parameters, **defaults},
data=data
)
12 changes: 6 additions & 6 deletions packmol_step/packmol_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import packmol_step


class PACKMOLStep(object):
class PackmolStep(object):
my_description = {
'description': 'An interface for PACKMOL',
'description': 'An interface for Packmol',
'group': 'Building',
'name': 'PACKMOL'
'name': 'Packmol'
}

def __init__(self, flowchart=None, gui=None):
Expand All @@ -25,12 +25,12 @@ def __init__(self, flowchart=None, gui=None):
def description(self):
"""Return a description of what this extension does
"""
return PACKMOLStep.my_description
return PackmolStep.my_description

def create_node(self, flowchart=None, **kwargs):
"""Return the new node object"""
return packmol_step.PACKMOL(flowchart=flowchart, **kwargs)
return packmol_step.Packmol(flowchart=flowchart, **kwargs)

def create_tk_node(self, canvas=None, **kwargs):
"""Return the graphical Tk node object"""
return packmol_step.TkPACKMOL(canvas=canvas, **kwargs)
return packmol_step.TkPackmol(canvas=canvas, **kwargs)
12 changes: 6 additions & 6 deletions packmol_step/tk_packmol.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

"""The graphical part of a PACKMOL step"""
"""The graphical part of a Packmol step"""

import logging
import seamm
Expand All @@ -13,8 +13,8 @@
logger = logging.getLogger(__name__)


class TkPACKMOL(seamm.TkNode):
"""Graphical interface for using PACKMOL for fluid boxes
class TkPackmol(seamm.TkNode):
"""Graphical interface for using Packmol for fluid boxes
"""

def __init__(
Expand Down Expand Up @@ -50,7 +50,7 @@ def create_dialog(self):
self.toplevel,
buttons=('OK', 'Help', 'Cancel'),
master=self.toplevel,
title='Edit PACKMOL step',
title='Edit Packmol step',
command=self.handle_dialog
)
self.dialog.withdraw()
Expand All @@ -76,7 +76,7 @@ def create_dialog(self):
self.reset_dialog()

def reset_dialog(self, widget=None):
methods = packmol_step.PACKMOL_Parameters.methods
methods = packmol_step.Packmol_Parameters.methods

method = self['method'].get()
submethod = self['submethod'].get()
Expand Down Expand Up @@ -154,7 +154,7 @@ def right_click(self, event):
self.popup_menu.tk_popup(event.x_root, event.y_root, 0)

def edit(self):
"""Present a dialog for editing the PACKMOL input
"""Present a dialog for editing the Packmol input
"""
if self.dialog is None:
self.create_dialog()
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
],
entry_points={
'org.molssi.seamm': [
'PACKMOL = packmol_step:PACKMOLStep',
'Packmol = packmol_step:PackmolStep',
],
'org.molssi.seamm.tk': [
'PACKMOL = packmol_step:PACKMOLStep',
'Packmol = packmol_step:PackmolStep',
],
}
)

0 comments on commit f05066e

Please sign in to comment.