Source file smi.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

(* read one molecule from a SMILES file *)
let read_one (input: in_channel): string =
  let line = input_line input in
  (* strip protects against trailing '\r'
     we append '\n' because all other formats
     end molecules with a '\n' *)
  (BatString.strip line) ^ "\n"

let get_name smiles_line =
  let _smiles, name =
    try BatString.split smiles_line ~by:"\t"
    with Not_found -> failwith "Smi.get_name: smiles file not using tabs" in
  (* all other file formats expect molecule name only,
   * not molecule name followed by EOL *)
  if BatString.ends_with name "\r\n" then
    BatString.rchop ~n:2 name
  else if BatString.ends_with name "\n" then
    BatString.rchop ~n:1 name
  else
    name