Skip to content

Commit

Permalink
Added a solution CLI.
Browse files Browse the repository at this point in the history
  • Loading branch information
lewispurigenbio committed Oct 31, 2020
1 parent 23d94fc commit 8dffedf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
30 changes: 15 additions & 15 deletions ionize/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ def ion(name):
click.echo(Database()[name].serialize(nested=False, compact=True))


# @cli.command()
# @click.option('--ion', '-i', multiple=True)
# @click.option('--concentration', '-c', multiple=True, type=float)
# def solution(ion, concentration):
# sol = Solution(ion, concentration)
# click.echo('pH: {:0.4f}'.format(sol.pH))
# click.echo('ionic strength: {:0.4f} M'.format(sol.ionic_strength))
# click.echo('conductivity: {:0.4f} s/M'.format(sol.conductivity()))
# click.echo('Debye length: {:0.4f} um'.format(sol.debye()*1e6))
# click.echo(dir(sol))
#
#
# @cli.command()
# def io():
# pass
@cli.command()
@click.option('--serialize', '-s', is_flag=True)
@click.argument("components", nargs=-1)
def solution(components, serialize):
ions = components[::2]
concentrations = [float(c) for c in components[1::2]]
assert len(ions) == len(concentrations), "There must be a concentration for each ion."
sol = Solution(ions, concentrations)
if serialize:
click.echo(sol.serialize(nested=False, compact=True))
else:
click.echo('pH: {:0.4f}'.format(sol.pH))
click.echo('ionic strength: {:0.4f} M'.format(sol.ionic_strength))
click.echo('conductivity: {:0.4f} s/M'.format(sol.conductivity()))
click.echo('Debye length: {:0.4f} um'.format(sol.debye()*1e6))

if __name__ == '__main__':
cli()
4 changes: 4 additions & 0 deletions ionize/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@ def test_ion_cli(self):
result = runner.invoke(cli, ['ion', 'tris'])
self.assertEqual(result.exit_code, 0)

def test_solution_cli(self):
runner = CliRunner()
result = runner.invoke(cli, ['solution', 'tris', '0.1', 'chloride', '0.05'])
self.assertEqual(result.exit_code, 0)

if __name__ == '__main__':
unittest.main()

0 comments on commit 8dffedf

Please sign in to comment.