Skip to content

Commit

Permalink
Merge pull request #6 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 f7dfdc1 + 9b04d1f commit c63dd03
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 27 deletions.
18 changes: 13 additions & 5 deletions from_smiles_step/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-

"""Top-level package for From SMILES step."""

__author__ = """Paul Saxe"""
__email__ = '[email protected]'
__version__ = '0.1.0'
"""
from_smiles_step
A step for generating a structure from a SMILES string.
"""

# Bring up the classes so that they appear to be directly in
# the package.
Expand All @@ -13,3 +12,12 @@
from from_smiles_step.from_smiles import FromSMILES # noqa: F401
from from_smiles_step.from_smiles_parameters import FromSMILESParameters # noqa: F401 E501
from from_smiles_step.tk_from_smiles import TkFromSMILES # 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
64 changes: 42 additions & 22 deletions from_smiles_step/from_smiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,51 @@ def __init__(self, flowchart=None, extension=None):

self.parameters = from_smiles_step.FromSMILESParameters()

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.
@property
def version(self):
"""The semantic version of this module.
"""
return from_smiles_step.__version__

next_node = super().describe(indent, json_dict)
@property
def git_revision(self):
"""The git version of this module.
"""
return from_smiles_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.
"""

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

if P['smiles string'][0] == '$':
job.job(
__("Create the structure from the SMILES in the variable"
" '{smiles string}'",
**P, indent=self.indent + ' ')
text = (
"Create the structure from the SMILES in the variable"
" '{smiles string}'."
)
else:
job.job(
__("Create the structure from the SMILES '{smiles string}'",
**P, indent=self.indent + ' ')
)
text = "Create the structure from the SMILES '{smiles string}'"

return next_node
if isinstance(P['minimize'], bool) and P['minimize']:
text += "The structure will be minimized"
text += " with the '{forcefield}' forcefield."
elif isinstance(P['minimize'], str) and P['minimize'][0] == '$':
text += "The structure will be minimized if '{minimize}' is true"
text += " with the '{forcefield}' forcefield."

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

def run(self):
"""Create 3-D structure from a SMILES string
Expand All @@ -77,18 +99,15 @@ def run(self):
context=seamm.flowchart_variables._data
)

# Print what we are doing
printer.important(self.description_text(P))

if P['smiles string'] is None or P['smiles string'] == '':
return None

local = seamm.ExecLocal()
smiles = P['smiles string']

# Print what we are doing
printer.important(
__("Creating the structure from the SMILES '{smiles}'",
smiles=smiles, indent=' ')
)

result = local.run(
cmd=['obabel', '--gen3d', '-ismi', '-omol'],
input_data=smiles
Expand Down Expand Up @@ -186,9 +205,10 @@ def run(self):

# Finish the output
printer.important(
__(" Created a molecular structure with {n_atoms} atoms.",
__(" Created a molecular structure with {n_atoms} atoms.\n",
n_atoms=len(structure['atoms']['elements']),
indent=' ')
)
printer.important('')

return next_node

0 comments on commit c63dd03

Please sign in to comment.