Source file bond.ml

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

(* very small bond module to help compute atom environments (a la molprint2d) from MOL2 files *)

open Printf

type t = { idx: int ;
           src: int ;
           dst: int }

(* indexes start at 1 in the MOL2 file format *)
let create (idx: int) (src: int) (dst: int): t =
  { idx = idx - 1; src = src - 1; dst = dst - 1 }

let dummy = create (-1) (-1) (-1)

(* example line (output of OpenBabel):
   "     1     1    11   ar" *)
let of_mol2_line l =
  try Scanf.sscanf l " %d %d %d %s"
        (fun idx src dst _bullshit -> create idx src dst)
  with _ -> failwith ("Bond.of_mol2_line: could not parse: " ^ l)

let to_string (a: t): string =
  sprintf "%d %d %d" a.idx a.src a.dst