-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ee28e6
commit b981c9e
Showing
6 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import argparse | ||
from rich.console import Console | ||
|
||
from . import utils | ||
from . import force_fields | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description="Plot potentials.", | ||
prog="fields", | ||
epilog="Created by Pedro Juan Royo @UnstrayCato" | ||
) | ||
parser.set_defaults(which="main") | ||
|
||
parser.add_argument( | ||
"--version", "-v", action="version", version="%(prog)s v0.17.0" | ||
) | ||
|
||
available_fields = [a.value for a in utils.Fields] | ||
parser.add_argument( | ||
"--field", "-f", nargs="*", choices=available_fields, | ||
help="Force field to plot" | ||
) | ||
|
||
args = parser.parse_args() | ||
print(args) | ||
|
||
console = Console() | ||
if args.which == "main": | ||
with console.status("[bold green]Plot created"): | ||
force_fields.plot_field(points = utils.create_range(0.9,3,60), | ||
epsilon = 1, sigma = 1.0, cut = 3.5) | ||
else: | ||
parser.print_help() | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from matplotlib import pyplot as plt | ||
|
||
from . import utils | ||
|
||
def get_field_data( | ||
field: utils.Fields, points: list[float], **kwargs | ||
) -> list[float]: | ||
"""Get the values for some points in a field""" | ||
if field == utils.Fields.LJ_CUT: | ||
# print("lj/cut field") | ||
return utils.lj_cut(points, **kwargs) | ||
else: | ||
raise NotImplementedError(f'Field {field} not implemented') | ||
|
||
def plot_field( | ||
field: utils.Fields = utils.Fields.LJ_CUT, | ||
points: list[float] = utils.create_range(), | ||
**kwargs | ||
) -> None: | ||
"""Plot a field""" | ||
|
||
x = points | ||
y = get_field_data(field, points, **kwargs) | ||
# print(x, len(x)) | ||
# print(y) | ||
|
||
plt.plot(x, y, 'o-') | ||
plt.show(block=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from enum import Enum | ||
|
||
class Fields(Enum): | ||
LJ_CUT = 'lj/cut' | ||
|
||
def create_range( | ||
start: float = 0.1, end: float = 3.0, items: int = 30 | ||
) -> list[float]: | ||
"""Return a float range between 'start' and 'end'""" | ||
# Check end is bigger than start | ||
if start > end: | ||
raise ValueError("start value is bigger than end value") | ||
|
||
# Check that items is bigger than 1 | ||
if items <= 1: | ||
raise ValueError("items value must be bigger than 1") | ||
|
||
step_val = (end - start) / (items - 1) | ||
range_vals = [] | ||
for i in range(items): | ||
range_vals.append(start + step_val*i) | ||
|
||
return range_vals | ||
|
||
def lj_cut( | ||
points: list[float], epsilon: float, sigma: float, cut: float | ||
) -> list[float | None]: | ||
"""Lennard-Jones potential with a cut-off at `cut`""" | ||
|
||
values = [] | ||
for r in points: | ||
if r < cut: | ||
values.append(4 * epsilon * ((sigma / r) ** 12 - (sigma / r) ** 6)) | ||
else: | ||
values.append(None) | ||
|
||
return values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from pu_pjr.force_fields_plotting import utils | ||
|
||
import pytest | ||
|
||
def test_create_range(): | ||
assert [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.7999999999999999, 0.8999999999999999, | ||
0.9999999999999999, 1.0999999999999999, 1.2, 1.3, 1.4, 1.5, | ||
1.5999999999999999, 1.7, 1.8, 1.9, 2.0, 2.0999999999999996, | ||
2.1999999999999997, 2.3, 2.4, 2.5, 2.6, 2.6999999999999997, | ||
2.8, 2.9, 3.0] == \ | ||
utils.create_range() | ||
assert [0, 1.0] == utils.create_range(0.0, 1.0, 2) | ||
with pytest.raises(ValueError): | ||
utils.create_range(1, 0) |