mirror of
https://github.com/QuantumPackage/qp2.git
synced 2024-12-21 11:03:29 +01:00
This commit is contained in:
parent
ecfdaf9eea
commit
de288449f5
@ -22,10 +22,15 @@ let of_string ~units s =
|
||||
}
|
||||
| [ name; x; y; z ] ->
|
||||
let e = Element.of_string name in
|
||||
{ element = e ;
|
||||
charge = Element.to_charge e;
|
||||
coord = Point3d.of_string ~units (String.concat " " [x; y; z])
|
||||
}
|
||||
begin
|
||||
try
|
||||
{ element = e ;
|
||||
charge = Element.to_charge e;
|
||||
coord = Point3d.of_string ~units (String.concat " " [x; y; z])
|
||||
}
|
||||
with
|
||||
| err -> (Printf.eprintf "name = \"%s\"\nxyz = (%s,%s,%s)\n%!" name x y z ; raise err)
|
||||
end
|
||||
| _ -> raise (AtomError s)
|
||||
|
||||
|
||||
|
@ -142,13 +142,21 @@ let of_xyz_string
|
||||
result
|
||||
|
||||
|
||||
let regexp_r = Str.regexp {|
|}
|
||||
let regexp_t = Str.regexp {| |}
|
||||
|
||||
|
||||
let of_xyz_file
|
||||
?(charge=(Charge.of_int 0)) ?(multiplicity=(Multiplicity.of_int 1))
|
||||
?(units=Units.Angstrom)
|
||||
filename =
|
||||
let lines =
|
||||
match Io_ext.input_lines filename with
|
||||
Io_ext.input_lines filename
|
||||
|> List.map (fun s -> Str.global_replace regexp_r "" s)
|
||||
|> List.map (fun s -> Str.global_replace regexp_t " " s)
|
||||
in
|
||||
let lines =
|
||||
match lines with
|
||||
| natoms :: title :: rest ->
|
||||
let natoms =
|
||||
try
|
||||
@ -173,6 +181,8 @@ let of_zmt_file
|
||||
?(units=Units.Angstrom)
|
||||
filename =
|
||||
Io_ext.read_all filename
|
||||
|> Str.global_replace regexp_r ""
|
||||
|> Str.global_replace regexp_t " "
|
||||
|> Zmatrix.of_string
|
||||
|> Zmatrix.to_xyz_string
|
||||
|> of_xyz_string ~charge ~multiplicity ~units
|
||||
|
@ -24,7 +24,9 @@ let of_string ~units s =
|
||||
let l = s
|
||||
|> String_ext.split ~on:' '
|
||||
|> List.filter (fun x -> x <> "")
|
||||
|> list_map float_of_string
|
||||
|> list_map (fun x ->
|
||||
try float_of_string x with
|
||||
| Failure msg -> (Printf.eprintf "Bad string: \"%s\"\n%!" x ; failwith msg) )
|
||||
|> Array.of_list
|
||||
in
|
||||
{ x = l.(0) *. f ;
|
||||
|
Loading…
Reference in New Issue
Block a user