Skip to content

Commit

Permalink
First working version of cleed called from Python.
Browse files Browse the repository at this point in the history
  • Loading branch information
yakutovicha committed Jul 24, 2024
1 parent b35f9bf commit c704a9f
Show file tree
Hide file tree
Showing 9 changed files with 456 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ dkms.conf

# CMake builds
cmake-build*/
cleedpy/cleed/bin/

# Vscode
.vscode/
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
- id: autoflake

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 24.4.2
hooks:
- id: black
language_version: python3
Expand Down
2 changes: 1 addition & 1 deletion cleedpy/cleed/src/leed.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "leed.h"

real ** leed(
char * bul_file,
char * par_file,
char * bul_file,
char *res_file
){
struct cryst_str *bulk=NULL;
Expand Down
17 changes: 16 additions & 1 deletion cleedpy/cli/leed.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import typer

from ..config import load_parameters
from ..interface.cleed import call_cleed
from ..physics.constants import BOHR_TO_ANGSTROM
from ..preprocess import extract_bulk_parameters, transform_cells


def leed(inptut_file: Path):
def leed_bak(inptut_file: Path):
"""Leed CLI."""
config = load_parameters(inptut_file)
transformation_matrix = transform_cells(config)
Expand All @@ -24,6 +25,20 @@ def leed(inptut_file: Path):
)


def leed(
parameters_file: str = typer.Option( # noqa: B008
"leed.inp", "--input", "-i", help="Input file with parameters"
),
bulk_file: str = typer.Option(None, "--bulk", "-b", help="Bulk file"), # noqa: B008
output_file: str = typer.Option( # noqa: B008
"leed.out", "--output", "-o", help="Output file"
), # noqa: B008
):
"""Leed CLI."""
result = call_cleed(parameters_file, bulk_file, output_file)
print(result)


def cli():
"""Leed CLI."""
typer.run(leed)
Expand Down
17 changes: 7 additions & 10 deletions cleedpy/interface/cleed.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,17 @@ def get_cleed_lib() -> CDLL:
return cdll.LoadLibrary(cleed_lib)


def call_cleed() -> None:
def call_cleed(parameters_file, bulk_file, output_file):
lib = get_cleed_lib()

lib.my_test_function.argtypes = [c_int, c_int, POINTER(Crystal)]
lib.my_test_function.restype = c_int
lib.leed.argtypes = [c_char_p, c_char_p, c_char_p]
lib.leed.restype = POINTER(POINTER(c_double))

bulk = Crystal()
bulk.vr = 1.0
bulk.vi = 2.0
bulk.temp = 300.0

bulk.a = (0.0, 1.0, 2.0, 3.0, 4.0)
result = lib.leed(
parameters_file.encode(), bulk_file.encode(), output_file.encode()
)

print("Result is ", lib.my_test_function(1, 2, bulk))
return result


if __name__ == "__main__":
Expand Down
201 changes: 201 additions & 0 deletions examples/cleedpy_example_intermediate/PHASE/Cu_BVH.phs
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
100 9 neng lmax (Cu, 60.70 amu, potential (WAKOH) from potpsb., zero at MT radius)
.2000
-.4004 -.0443 .0230 .0001 .0000 .0000 .0000 .0000 .0000
.4000
-.5627 -.0991 .5529 .0007 .0000 .0000 .0000 .0000 .0000
.6000
-.6868 -.1495 2.7533 .0026 .0001 .0000 .0000 .0000 .0000
.8000
-.7921 -.1948 2.8340 .0067 .0002 .0000 .0000 .0000 .0000
1.0000
-.8858 -.2357 2.8434 .0137 .0006 .0000 .0000 .0000 .0000
1.2000
-.9716 -.2738 2.8423 .0242 .0013 .0001 .0000 .0000 .0000
1.4000
-1.0516 -.3099 2.8409 .0390 .0024 .0001 .0000 .0000 .0000
1.6000
-1.1269 -.3450 2.8420 .0584 .0041 .0002 .0000 .0000 .0000
1.8000
-1.1983 -.3795 2.8461 .0829 .0065 .0004 .0000 .0000 .0000
2.0000
-1.2665 -.4139 2.8532 .1126 .0097 .0007 .0000 .0000 .0000
2.2000
-1.3317 -.4482 2.8627 .1475 .0138 .0011 .0001 .0000 .0000
2.4000
-1.3942 -.4825 2.8739 .1872 .0190 .0017 .0001 .0000 .0000
2.6000
-1.4543 -.5169 2.8860 .2313 .0253 .0025 .0002 .0000 .0000
2.8000
-1.5121 -.5513 2.8983 .2789 .0329 .0035 .0003 .0000 .0000
3.0000
-1.5678 -.5856 2.9103 .3291 .0417 .0047 .0004 .0000 .0000
3.2000
-1.6214 -.6197 2.9213 .3806 .0518 .0063 .0006 .0000 .0000
3.4000
-1.6731 -.6536 2.9311 .4325 .0633 .0082 .0008 .0001 .0000
3.6000
-1.7229 -.6871 2.9394 .4836 .0760 .0104 .0011 .0001 .0000
3.8000
-1.7710 -.7201 2.9460 .5330 .0901 .0131 .0015 .0001 .0000
4.0000
-1.8173 -.7527 2.9509 .5800 .1053 .0162 .0020 .0002 .0000
4.2000
-1.8620 -.7846 2.9542 .6241 .1216 .0197 .0026 .0003 .0000
4.4000
-1.9052 -.8160 2.9559 .6652 .1389 .0238 .0032 .0003 .0000
4.6000
-1.9468 -.8466 2.9563 .7031 .1570 .0283 .0040 .0005 .0000
4.8000
-1.9869 -.8766 2.9554 .7379 .1758 .0333 .0050 .0006 .0001
5.0000
-2.0256 -.9058 2.9534 .7699 .1951 .0389 .0061 .0007 .0001
5.2000
-2.0630 -.9342 2.9505 .7993 .2147 .0449 .0074 .0009 .0001
5.4000
-2.0991 -.9619 2.9468 .8264 .2345 .0515 .0088 .0012 .0001
5.6000
-2.1339 -.9887 2.9425 .8515 .2542 .0585 .0105 .0015 .0002
5.8000
-2.1675-1.0148 2.9378 .8748 .2739 .0661 .0123 .0018 .0002
6.0000
-2.2000-1.0401 2.9327 .8967 .2932 .0741 .0144 .0022 .0003
6.2000
-2.2314-1.0646 2.9274 .9174 .3120 .0825 .0166 .0026 .0003
6.4000
-2.2618-1.0883 2.9219 .9371 .3303 .0914 .0191 .0031 .0004
6.6000
-2.2911-1.1113 2.9164 .9560 .3480 .1005 .0219 .0037 .0005
6.8000
-2.3195-1.1335 2.9110 .9742 .3650 .1101 .0248 .0044 .0006
7.0000
-2.3470-1.1550 2.9056 .9920 .3813 .1198 .0281 .0051 .0007
7.2000
-2.3737-1.1759 2.9003 1.0094 .3968 .1298 .0315 .0059 .0009
7.4000
-2.3996-1.1960 2.8952 1.0264 .4115 .1400 .0353 .0068 .0010
7.6000
-2.4247-1.2156 2.8903 1.0432 .4255 .1503 .0392 .0079 .0012
7.8000
-2.4491-1.2345 2.8857 1.0598 .4387 .1607 .0434 .0090 .0015
8.0000
-2.4728-1.2528 2.8812 1.0761 .4513 .1711 .0478 .0102 .0017
8.2000
-2.4959-1.2707 2.8770 1.0922 .4631 .1815 .0525 .0116 .0020
8.4000
-2.5184-1.2880 2.8730 1.1081 .4744 .1918 .0574 .0130 .0023
8.6000
-2.5404-1.3048 2.8693 1.1238 .4850 .2019 .0625 .0146 .0027
8.8000
-2.5619-1.3212 2.8657 1.1392 .4952 .2120 .0677 .0163 .0031
9.0000
-2.5829-1.3371 2.8624 1.1542 .5048 .2218 .0732 .0182 .0035
9.2000
-2.6034-1.3527 2.8592 1.1690 .5141 .2315 .0788 .0201 .0040
9.4000
-2.6236-1.3680 2.8562 1.1833 .5230 .2408 .0846 .0222 .0045
9.6000
-2.6433-1.3829 2.8533 1.1973 .5315 .2500 .0905 .0244 .0051
9.8000
-2.6627-1.3975 2.8505 1.2109 .5398 .2588 .0965 .0268 .0058
10.0000
-2.6818-1.4118 2.8479 1.2240 .5479 .2673 .1026 .0293 .0065
10.2000
-2.7006-1.4259 2.8452 1.2366 .5558 .2756 .1088 .0319 .0072
10.4000
-2.7191-1.4397 2.8427 1.2487 .5635 .2835 .1151 .0347 .0081
10.6000
-2.7373-1.4533 2.8401 1.2604 .5711 .2911 .1213 .0376 .0089
10.8000
-2.7553-1.4668 2.8375 1.2715 .5786 .2984 .1276 .0406 .0099
11.0000
-2.7730-1.4801 2.8350 1.2821 .5860 .3054 .1339 .0437 .0109
11.2000
-2.7905-1.4932 2.8324 1.2923 .5935 .3121 .1402 .0470 .0120
11.4000
-2.8078-1.5061 2.8297 1.3019 .6008 .3186 .1465 .0503 .0132
11.6000
-2.8249-1.5190 2.8270 1.3111 .6082 .3247 .1526 .0538 .0144
11.8000
-2.8418-1.5317 2.8243 1.3198 .6156 .3306 .1587 .0574 .0157
12.0000
-2.8585-1.5442 2.8215 1.3281 .6230 .3363 .1648 .0610 .0171
12.2000
-2.8750-1.5567 2.8185 1.3360 .6303 .3418 .1707 .0648 .0186
12.4000
-2.8914-1.5691 2.8156 1.3434 .6377 .3470 .1765 .0686 .0202
12.6000
-2.9076-1.5813 2.8125 1.3505 .6451 .3521 .1822 .0725 .0218
12.8000
-2.9236-1.5935 2.8093 1.3573 .6525 .3570 .1878 .0765 .0235
13.0000
-2.9395-1.6056 2.8061 1.3638 .6599 .3617 .1932 .0805 .0253
13.2000
-2.9552-1.6176 2.8028 1.3699 .6673 .3663 .1985 .0845 .0271
13.4000
-2.9707-1.6294 2.7994 1.3758 .6746 .3708 .2037 .0886 .0291
13.6000
-2.9861-1.6412 2.7960 1.3815 .6820 .3752 .2086 .0928 .0311
13.8000
-3.0013-1.6529 2.7925 1.3870 .6893 .3795 .2135 .0969 .0332
14.0000
-3.0163-1.6645 2.7889 1.3922 .6965 .3837 .2182 .1011 .0353
14.2000
-3.0312-1.6760 2.7853 1.3973 .7036 .3879 .2227 .1052 .0376
14.4000
-3.0460-1.6874 2.7817 1.4022 .7107 .3920 .2271 .1094 .0399
14.6000
-3.0606-1.6987 2.7780 1.4070 .7177 .3961 .2313 .1135 .0422
14.8000
-3.0750-1.7098 2.7743 1.4117 .7246 .4001 .2354 .1176 .0447
15.0000
-3.0892-1.7209 2.7706 1.4163 .7314 .4042 .2393 .1217 .0471
15.2000
-3.1033-1.7319 2.7669 1.4208 .7380 .4082 .2431 .1258 .0497
15.4000
-3.1173-1.7427 2.7632 1.4252 .7446 .4122 .2468 .1298 .0523
15.6000
-3.1310-1.7534 2.7595 1.4295 .7510 .4163 .2503 .1337 .0549
15.8000
-3.1446-1.7640 2.7558 1.4338 .7572 .4204 .2537 .1376 .0576
16.0000
-3.1581-1.7745 2.7521 1.4381 .7633 .4244 .2571 .1414 .0604
16.2000
-3.1714-1.7849 2.7485 1.4422 .7692 .4285 .2603 .1452 .0632
16.4000
-3.1845-1.7951 2.7449 1.4464 .7750 .4327 .2634 .1489 .0660
16.6000
-3.1974-1.8053 2.7414 1.4505 .7807 .4368 .2664 .1525 .0688
16.8000
-3.2102-1.8153 2.7379 1.4545 .7862 .4410 .2693 .1560 .0717
17.0000
-3.2228-1.8251 2.7344 1.4586 .7915 .4452 .2722 .1595 .0745
17.2000
-3.2353-1.8349 2.7310 1.4625 .7966 .4494 .2750 .1628 .0774
17.4000
-3.2476-1.8445 2.7277 1.4665 .8017 .4536 .2777 .1661 .0803
17.6000
-3.2598-1.8539 2.7244 1.4704 .8065 .4578 .2804 .1694 .0832
17.8000
-3.2718-1.8633 2.7212 1.4742 .8113 .4621 .2830 .1724 .0862
18.0000
-3.2836-1.8725 2.7180 1.4780 .8158 .4663 .2856 .1755 .0891
18.2000
-3.2953-1.8816 2.7149 1.4818 .8203 .4705 .2882 .1784 .0920
18.4000
-3.3068-1.8906 2.7119 1.4855 .8246 .4748 .2907 .1813 .0949
18.6000
-3.3182-1.8994 2.7089 1.4891 .8288 .4791 .2933 .1840 .0978
18.8000
-3.3294-1.9081 2.7060 1.4927 .8329 .4833 .2958 .1867 .1006
19.0000
-3.3405-1.9167 2.7032 1.4962 .8369 .4875 .2983 .1893 .1035
19.2000
-3.3515-1.9252 2.7004 1.4996 .8408 .4917 .3008 .1918 .1063
19.4000
-3.3623-1.9335 2.6977 1.5030 .8446 .4958 .3032 .1943 .1091
19.6000
-3.3730-1.9418 2.6950 1.5062 .8483 .4999 .3057 .1966 .1118
19.8000
-3.3836-1.9499 2.6924 1.5094 .8519 .5040 .3083 .1990 .1145
20.0000
-3.3940-1.9579 2.6899 1.5125 .8555 .5081 .3108 .2012 .1172
Loading

0 comments on commit c704a9f

Please sign in to comment.