123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293(* Copyright (C) 2020, Francois Berenger
Yamanishi laboratory,
Department of Bioscience and Bioinformatics,
Faculty of Computer Science and Systems Engineering,
Kyushu Institute of Technology,
680-4 Kawazu, Iizuka, Fukuoka, 820-8502, Japan. *)(* atom environment *)openPrintfmoduleL=BatListmoduleLog=Dolog.Log(* layer = (depth, counted-atoms) *)typelayer=int*((PiEltHA.t*int)list)(* center-atom layers *)typet=layerlistletcounted_types_to_string(l:(PiEltHA.t*int)list):string=letbuff=Buffer.create80inL.iteri(funi(x,count)->bprintfbuff(ifi=0then"%s:%d"else",%s:%d")(PiEltHA.to_stringx)count)l;Buffer.contentsbuffletcounted_types_of_string(s:string):(PiEltHA.t*int)list=letstrings=BatString.split_on_strings~by:","inL.map(funstr->Scanf.sscanfstr"%s:%d"Utls.make_pair)stringsletlayer_to_string((depth,counted_types):layer):string=sprintf"%d_%s"depth(counted_types_to_stringcounted_types)letlayer_of_string(str:string):layer=Scanf.sscanfstr"%d_%s"(funds->(d,counted_types_of_strings))letto_string(layers:t):string=letbuff=Buffer.create80inL.iteri(funilayer->bprintfbuff(ifi=0then"%s"else";%s")(layer_to_stringlayer))layers;Buffer.contentsbuffletof_string(s:string):t=letlayer_strings=BatString.split_on_strings~by:";"inL.maplayer_of_stringlayer_strings(* parse the 1st line of a .idx file *)letparse_index_commentfn=letheader,index_lines=Utls.maybe_extract_comment_headerfninmatchheaderwith|None->(-1,[])|Somecomment->letradius=Scanf.sscanfcomment"#radius=%d"(funr->r)in(radius,index_lines)(* parse the 1st line of a .mop2d file *)letparse_molecules_commentfn=letheader,mol_lines=Utls.maybe_extract_comment_headerfninmatchheaderwith|None->(-1,"/dev/null",mol_lines)|Somecomment->letradius,index_fn=Scanf.sscanfcomment"#radius=%d;index=%s"(funrfn->(r,fn))in(radius,index_fn,mol_lines)(* parse the 1st line of an already opened .mop2d file
(and advance the file pointer) *)letparse_commentinput=try(* we are parsing a valid .mop2d file *)Scanf.sscanf(input_lineinput)"#radius=%d;index=%s"(funrfn->(r,fn))with(* we are not *)Scanf.Scan_failure_->(-1,"/dev/null")(* extract the MOP2D atom env. to bitstring index HT *)letrestore_mop2d_indexfn=letradius,index_lines=parse_index_commentfninletmop2d_envs=L.mapof_stringindex_linesinletres=Hashtbl.create11inL.iteri(funienv->(* eprintf "%s\n" (Mop2d_env.to_string env); *)assert(not(Hashtbl.memresenv));Hashtbl.addresenvi)mop2d_envs;Log.info"index size: %d"(Hashtbl.lengthres);(radius,res)