mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-12-22 20:35:44 +01:00
Fixed string -> str in Jastrow
This commit is contained in:
parent
94fb57b9ea
commit
0ad057f77b
@ -62,6 +62,25 @@ def make_functions():
|
||||
with open(json_file,'r') as f:
|
||||
data = json.load(f)
|
||||
|
||||
convert_r = { "int": "i64",
|
||||
"int special" : "usize",
|
||||
"float" : "f64",
|
||||
"float sparse" : "f64",
|
||||
"float buffered" : "f64",
|
||||
"dim" : "usize",
|
||||
"dim readonly" : "usize",
|
||||
"index" : "usize",
|
||||
"string" : "string"}
|
||||
|
||||
convert_c = { "int": "i64",
|
||||
"int special" : "i64",
|
||||
"float" : "f64",
|
||||
"float sparse" : "f64",
|
||||
"float buffered" : "f64",
|
||||
"dim" : "i64",
|
||||
"dim readonly" : "i64",
|
||||
"index" : "i64",
|
||||
"string" : "string"}
|
||||
r = []
|
||||
|
||||
for group in data:
|
||||
@ -79,6 +98,8 @@ pub fn has_{group_l}(trex_file: File) -> Result<bool, ExitCode> {
|
||||
.replace("{group}",group)
|
||||
.replace("{group_l}",group_l) ]
|
||||
for element in data[group]:
|
||||
type_c = convert_c[data[group][element][0]]
|
||||
type_r = convert_r[data[group][element][0]]
|
||||
element_l = element.lower()
|
||||
r += [ """
|
||||
pub fn has_{group_l}_{element_l}(trex_file: File) -> Result<bool, ExitCode> {
|
||||
@ -95,6 +116,51 @@ pub fn has_{group_l}_{element_l}(trex_file: File) -> Result<bool, ExitCode> {
|
||||
.replace("{element}",element)
|
||||
.replace("{element_l}",element_l) ]
|
||||
|
||||
# Scalar elements
|
||||
if data[group][element][1] == []:
|
||||
if data[group][element][0] in [ "int", "float", "dim", "index" ]:
|
||||
r += [ """
|
||||
pub fn read_{group_l}_{element_l}(trex_file: File) -> Result<{type_r}, ExitCode> {
|
||||
let data = unsafe {
|
||||
let data_c: {type_c};
|
||||
let rc = c::trexio_read_{group}_{element}_64(trex_file, &data);
|
||||
data_c.try_into().unwrap();
|
||||
};
|
||||
rc_return(rc, data)
|
||||
}
|
||||
|
||||
pub fn write_{group_l}_{element_l}<T>(trex_file: File, data: T) -> Result<(), ExitCode>
|
||||
where {type_c}: From<T> {
|
||||
let data: {type_c} = data.try_into().unwrap();
|
||||
let rc = unsafe { c::trexio_write_{group}_{element}_64(trex_file, data) };
|
||||
rc_return(rc, ())
|
||||
}
|
||||
"""
|
||||
.replace("{type_c}",type_c)
|
||||
.replace("{group}",group)
|
||||
.replace("{group_l}",group_l)
|
||||
.replace("{element}",element)
|
||||
.replace("{element_l}",element_l) ]
|
||||
|
||||
elif data[group][element][0] in [ "string" ]:
|
||||
pass # TODO
|
||||
|
||||
elif data[group][element][0] in [ "dim readonly" ]:
|
||||
r += [ """
|
||||
pub fn write_{group_l}_{element_l}<T>(trex_file: File, data: T) -> Result<(), ExitCode>
|
||||
where {type_c}: From<T> {
|
||||
let data: {type_c} = data.try_into().unwrap();
|
||||
let rc = unsafe { c::trexio_write_{group}_{element}_64(trex_file, data) };
|
||||
rc_return(rc, ())
|
||||
}
|
||||
"""
|
||||
.replace("{type_c}",type_c)
|
||||
.replace("{group}",group)
|
||||
.replace("{group_l}",group_l)
|
||||
.replace("{element}",element)
|
||||
.replace("{element_l}",element_l) ]
|
||||
|
||||
|
||||
|
||||
with open(generated_rs,'w') as f:
|
||||
f.write('\n'.join(r))
|
||||
|
@ -63,12 +63,6 @@ pub fn inquire(file_name: &str) -> Result<bool, ExitCode> {
|
||||
include!("generated.rs");
|
||||
|
||||
|
||||
pub fn write_nucleus_num(trex_file: File, data: usize) -> Result<(), ExitCode> {
|
||||
let data: i64 = data.try_into().unwrap();
|
||||
let rc = unsafe { c::trexio_write_nucleus_num_64(trex_file, data) };
|
||||
rc_return(rc, ())
|
||||
}
|
||||
|
||||
pub fn write_nucleus_charge(trex_file: File, data: Vec<f64>) -> Result<(), ExitCode> {
|
||||
let size: i64 = data.len().try_into().unwrap();
|
||||
let rc = unsafe { c::trexio_write_safe_nucleus_charge_64(trex_file, data.as_ptr() as *const f64, size) };
|
||||
|
4
trex.org
4
trex.org
@ -1327,7 +1327,7 @@ power = [
|
||||
#+name: jastrow
|
||||
| Variable | Type | Dimensions | Description |
|
||||
|---------------+----------+---------------------+-----------------------------------------------------------------|
|
||||
| ~type~ | ~string~ | | Type of Jastrow factor: ~CHAMP~ or ~Mu~ |
|
||||
| ~type~ | ~str~ | | Type of Jastrow factor: ~CHAMP~ or ~Mu~ |
|
||||
| ~en_num~ | ~dim~ | | Number of Electron-nucleus parameters |
|
||||
| ~ee_num~ | ~dim~ | | Number of Electron-electron parameters |
|
||||
| ~een_num~ | ~dim~ | | Number of Electron-electron-nucleus parameters |
|
||||
@ -1345,7 +1345,7 @@ power = [
|
||||
:results:
|
||||
#+begin_src python :tangle trex.json
|
||||
"jastrow": {
|
||||
"type" : [ "string", [] ]
|
||||
"type" : [ "str" , [] ]
|
||||
, "en_num" : [ "dim" , [] ]
|
||||
, "ee_num" : [ "dim" , [] ]
|
||||
, "een_num" : [ "dim" , [] ]
|
||||
|
Loading…
Reference in New Issue
Block a user