Reading data for Moller - Plesset series

Mathematica program

(* Reading data for Moller - Plesset series *)

(* Finding the line starting with key and returning the rest of this line (after the key).
        Set of lines should be pre-defined.
        In addition, the variable linenumber is set to the number of the line  *)
finddata[key_String] := Module[{res, key0, mlines, line, line0, 
        mchar, line1, line10},
      res = Null;
      key0 = StringReplace[key, {" " -> "", "\t" -> ""}];
      mlines = Length[lines];
      Do[line = lines[[nline]];
        line0 = StringReplace[line, {" " -> "", "\t" -> ""}];
        If[StringMatchQ[line0, key0 <> "*", IgnoreCase -> True],
          linenumber = nline;
          mchar = StringLength[line];
          Do[
            line1 = StringTake[line, mchar - nchar];
            line10 = StringReplace[line1, {" " -> "", "\t" -> ""}];
            If[StringMatchQ[line10, key0, IgnoreCase -> True],
              res = StringTake[line, -nchar];
              Break[]
              ], {nchar, 0, mchar}];
          Break[]
          ], {nline, mlines}];
      res];

ndigitdata=256;
dirdata=ToFileName[{dirhome,"data"}];
ldirdata=StringLength[dirdata];
outputfiles=Sort[FileNames["output.dat",dirdata,Infinity]];
moutput=Length[outputfiles];
setprec[x_]:=ToExpression[ToString[x]<>"`"<>ToString[ndigitdata]];
plist={{"Name","Kind",{"Molecule","Basis"},"Energy"}};
Do[
    outputfile=outputfiles[[noutput]];
    outputdir=DirectoryName[outputfile];
    outputd=StringDrop[outputdir,ldirdata];
    outputd=StringReplace[outputd,"\\"->"/"];
    If[StringMatchQ[outputd,"*/"],outputd=StringDrop[outputd,-1]];
    l=StringPosition[outputd,"/"]//Last//Last;
    (*l2=StringPosition[outputd,"/"][[-2,1]];*)
    outputl=StringDrop[outputd,l];
    outputf=StringTake[outputd,l-1];
    (*outputl2=StringDrop[outputf,l2];*)
    inputfile=ToFileName[outputdir,"input.dat"];
    If[FileType[inputfile]=!=File,
      If[iprint>2,Print["--------------------------Warning: input file ",inputfile,
        " does not exist."]]];
    lines=Import[inputfile,"Lines"];
    iffci=finddata["fci="];
    ifmpn=finddata["mpn="];
    If[Head[iffci]===String,
      iffci=StringReplace[iffci,{" "->"","\t"->""}]//ToLowerCase];
    If[Head[ifmpn]===String,
      ifmpn=StringReplace[ifmpn,{" "->"","\t"->""}]//ToLowerCase];
    molec=finddata["label="]//ToExpression;
    bas=finddata["basis="]//ToExpression;
    nm00=finddata["maxnvect="]//ToExpression;
    lines=Import[outputfile,"Lines"];
    outlabel=finddata["LABEL="];
    escf=finddata["SCFEnergy(ref):"]//setprec;
    enuc=finddata["Nuclearrepulsionenergy:"]//setprec;
    eoneel=finddata["One-electronenergy:"]//setprec;
    etwoel=finddata["Two-electronenergy:"]//setprec;
    ecore=finddata["Frozencoreenergy:"]//setprec;
    etotel=finddata["Totalelectronicenergy:"]//setprec;
    etotscf=finddata["TotalSCFenergy:"]//setprec;
    ndets=finddata["CIvector/subblocklength="]//ToExpression;
    attr={escf,enuc,eoneel,etwoel,ecore,etotel,etotscf};
    If[
      (ifmpn==="true"||(ifmpn=!="false"&&NumberQ[nm00]))&&iffci=!="true",
      kind[outputfile]="MP";
      enscf=finddata["CalcInfo.escf="]//setprec;
      en0=finddata["CalcInfo.e0="]//setprec;
      ennuc=finddata["CalcInfo.enuc="]//setprec;
      en1=finddata["CalcInfo.e1="]//setprec;
      starttab=finddata["nCorr.EnergyE(MPn)nCorr.EnergyE(MPn)"];
      nm=2 nm00-1;
      en=Table[Null,{nm+1}];
      en[[1]]=
        ReadList[StringToStream[lines[[linenumber+1]]],Word][[3]]//setprec;
      en[[2]]=en1;
      Do[
        line=lines[[linenumber+n+2]];
        en[[n+1]]=ReadList[StringToStream[line],Word][[-2]]//setprec;
        ,{n,2,nm}];
      If[StringMatchQ[outputl,"mp*",IgnoreCase->True],name=outputf,
        If[iprint>2,Print["Warning: the output file ",outputfile,
          " is MPn-type, but has a parent directory different from MP*."]];
        name=outputd],
      kind[outputfile]="FCI";
      en=finddata["ROOT1ECI="]//setprec;
      If[StringMatchQ[outputl,"fci",IgnoreCase->True],name=outputf,
        If[iprint>2,Print["Warning: the output file ",outputfile,
          " is FCI-type, but has a parent directory different from FCI."]];
        name=outputd]
      ];
    attributes[outputfile]={name,molec,bas,nm00};
    energy[outputfile]=en;
    plist=Append[plist,
        {name,kind[outputfile],attributes[outputfile][[{2,3}]],
          Short[N[energy[outputfile]]]}],{noutput,moutput}];
names={};
Do[
    outputfile=outputfiles[[noutput]];
    outputdir=DirectoryName[outputfile];
    If[kind[outputfile]=!="MP",Continue[]];
    outputd=StringDrop[outputdir,ldirdata];
    outputd=StringReplace[outputd,"\\"->"/"];
    If[StringMatchQ[outputd,"*/"],outputd=StringDrop[outputd,-1]];
    l=StringPosition[outputd,"/"]//Last//Last;
    outputl=StringDrop[outputd,l];
    outputf=StringTake[outputd,l-1];
    {name,molec,bas,nm00}=attributes[outputfile];
    name=StringReplace[name,"/"->" "];
    names=Append[names,name];
    molecule[name]=molec;
    basis[name]=bas;
    structure[name]="";
    bdistance[name]=Undefined;
    en=energy[outputfile];
(* ! *)
    func=Prepend[Drop[en,2],en[[1]]+en[[2]]];
(*    func=en;*)
    nm0=Length[func];
    Do[If[func[[n]]==0,Break[]];
      nm=n,{n,nm0}];
    func=Take[func,nm];
    coeff[name]=func;
    exact[name]=Plus@@en;
    If[StringMatchQ[outputl,"mp*",IgnoreCase->True],
      fcifile=ToFileName[{ParentDirectory[outputdir],"fci"},"output.dat"];
      If[kind[fcifile]==="FCI",
        exact[name]=energy[fcifile],
        If[iprint>2,Print["Warning: No FCI-file ",fcifile]],
        If[iprint>2,Print["Warning: last directory of ",outputfile," is not mp*"]]
        ]
      ];
    accdig[name]=accDigits/@func;
    ,{noutput,moutput}];
names=Select[names,exact[#]!=0&];
mser=Length[names];
If[iprint>0,Print[{Range[mser], names} // Transpose // TableForm]];
If[iprint>1,Print[plist//TableForm]];
printprogr["read"];

Molecule - icon for Allen-dataBlankExamples of MP seriesBlankSource code of Mathematica programBlankMathematica programsBlankWork in UMass DartmouthWork in UMassDBlankWaste iconUnpublished reports

Designed by A. Sergeev.