当前位置: 首页 > 知识库问答 >
问题:

用find解析文件会给出不同文件的奇怪结果

万勇
2023-03-14
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>

void readFileToStrings(const std::string& filename, std::string& ParticlesString,
                       std::string& GaussianString, std::string& MOString) {
    std::ifstream source(filename);
    std::string line;
    while(std::getline(source, line)) {
        if(line.find("Molpro") != std::string::npos) {
            std::getline(source, line, '['); // reads until [
        }
        if(line.find("Atoms") != std::string::npos) {
            std::getline(source, line, '['); // reads until [
            ParticlesString.append(line);
        }
        if(line.find("GTO") != std::string::npos) {
            std::getline(source, line, '['); // reads until [
            GaussianString.append(line);
        }
        if(line.find("MO") != std::string::npos) {
            std::getline(source, line, '\0'); // reads until end of file
            MOString.append(line);
        }
    }
}

int main(int argc, char** argv) {
    if(argc != 2) {
        std::cerr << "USAGE: " << argv[0] << " <filename>\n";
        return 1;
    }
    std::string filename(argv[1]), ParticlesString, GaussianString, MOString;
    readFileToStrings(filename, ParticlesString, GaussianString, MOString);

    std::cout << ParticlesString << "\n";
}
[Molden Format]
[Atoms] (AU)
O    1    8         0.000000000000       0.000000000000      -0.124302651265
H    2    1         0.000000000000      -1.424704710000       0.986386639735
H    3    1        -0.000000000000       1.424704710000       0.986386639735
[GTO]
  1 0
 s    8  1.00
    11720.0000000000         0.0007100000
     1759.0000000000         0.0054700000
      400.8000000000         0.0278370000
      113.7000000000         0.1048000000
       37.0300000000         0.2830620000
       13.2700000000         0.4487190000
        5.0250000000         0.2709520000
        1.0130000000         0.0154580000
 s    8  1.00
    11720.0000000000        -0.0001600000
     1759.0000000000        -0.0012630000
      400.8000000000        -0.0062670000
      113.7000000000        -0.0257160000
       37.0300000000        -0.0709240000
       13.2700000000        -0.1654110000
        5.0250000000        -0.1169550000
        1.0130000000         0.5573680000
 s    1  1.00
        0.3023000000         1.0000000000
 p    3  1.00
       17.7000000000         0.0430180000
        3.8540000000         0.2289130000
        1.0460000000         0.5087280000
 p    1  1.00
        0.2753000000         1.0000000000
 d    1  1.00
        1.1850000000         1.0000000000

  2 0
 s    3  1.00
       13.0100000000         0.0196850000
        1.9620000000         0.1379770000
        0.4446000000         0.4781480000
 s    1  1.00
        0.1220000000         1.0000000000
 p    1  1.00
        0.7270000000         1.0000000000

  3 0
 s    3  1.00
       13.0100000000         0.0196850000
        1.9620000000         0.1379770000
        0.4446000000         0.4781480000
 s    1  1.00
        0.1220000000         1.0000000000
 p    1  1.00
        0.7270000000         1.0000000000

[5D]
[9G]

[MO]
 Sym= A1
 Ene= -2.05504193878478176e+01
 Spin= Alpha
 Occup=  2.00000000000000000e+00
  1  1.00090233711673782e+00
  2  1.18218569881159419e-03
  3 -2.65616439031917534e-03
  4  0.00000000000000000e+00
  5  0.00000000000000000e+00
  6  1.77146011704106335e-03
  7  0.00000000000000000e+00
  8  0.00000000000000000e+00
  9 -4.80000097346545279e-04
 10  1.39013834758571625e-05
 11  0.00000000000000000e+00
 12  0.00000000000000000e+00
 13 -1.39822026074492775e-04
 14  0.00000000000000000e+00
 15 -2.48316020753471748e-04
 16  4.20097131947155702e-04
 17  0.00000000000000000e+00
 18 -5.74904249836309948e-04
 19  4.87036596243491202e-04
 20 -2.48316020753471748e-04
 21  4.20097131947155702e-04
 22  0.00000000000000000e+00
 23  5.74904249836309948e-04
 24  4.87036596243491202e-04
 Sym= A1
 Ene= -1.33767141221376074e+00
 Spin= Alpha
 Occup=  2.00000000000000000e+00
  1  8.23750319287331126e-03
  2 -4.42693483105670693e-01
  3 -3.74498035531203644e-01
  4  0.00000000000000000e+00
  5  0.00000000000000000e+00
  6 -7.94258623925411383e-02
  7  0.00000000000000000e+00
  8  0.00000000000000000e+00
  9  1.34092445806940908e-02
 10 -1.29606223143065302e-03
 11  0.00000000000000000e+00
 12  0.00000000000000000e+00
 13  2.99830598541997798e-03
 14  0.00000000000000000e+00
 15 -1.94341522346533402e-01
 16 -1.00103187758395738e-02
 17  0.00000000000000000e+00
 18 -3.73152124438631272e-02
 19  2.06694627945085245e-02
 20 -1.94341522346533402e-01
 21 -1.00103187758395738e-02
 22  0.00000000000000000e+00
 23  3.73152124438631272e-02
 24  2.06694627945085245e-02

文件2:

[Molden Format]
[Molpro variables]
_NUMVAR=  897.0000000000000    
_AVOGAD= 0.6022136736000000E+24
_BOLTZ= 0.1380658000000000E-22
_CLIGHT=  29979245800.00000    
_EV= 0.3674932379085202E-01
_ENULL= 0.8854187817000000E-11
_KJOULE= 0.3808798324128737E-03
_KJOULE/MOL= 0.3808798324128737E-03
_CM= 0.4556335267302901E-05
_CM-1= 0.4556335267302901E-05
_DEB2SI= 0.3335641000000000E-29
_AMU2AU=  1822.888390000000    
_KCAL= 0.1593601117815568E-02
_KCAL/MOL= 0.1593601117815568E-02
_KELVIN= 0.3166811411060229E-05
_JOULE= 0.4359748200000000E-17
_HERTZ= 0.1519829846004524E-15
_HZ= 0.1519829846004524E-15
_JPCAL=  4.184000000000000    
_PLANCK= 0.6626075540000000E-33
_TOA= 0.5291772109200000    
_TOANG= 0.5291772109200000    
_TORAD= 0.1745329251994330E-01
_TOCM=  219474.6306700000    
_TODEBYE=  2.541580000000000    
_TOE= 0.4803242000000000E-09
_TOEV=  27.21138505000000    
_TOHERTZ=  6579683920729000.    
_TOHZ=  6579683920729000.    
_TOK=  315775.0400000000    
_TOKCAL=  627.5096000000000    
_TOKELVIN=  315775.0400000000    
_TOKJ=  2625.500000000000    
_TOKJOULE=  2625.500000000000    
_TOKG= 0.1660565586000000E-26
_ANG=  1.889726124565062    
_ANGSTROM=  1.889726124565062    
_RPAREF=  0.000000000000000    
_RPADISS=  0.000000000000000    
_IGNORE_UNDEF=  2.000000000000000    
_STRICTCHECK=  0.000000000000000    
_SEW_ONEEL=  0.000000000000000    
_CPPDONE=FALSE
_DKROLL_DONE=  0.000000000000000    
_FOCKDONE=TRUE
_GRADONE=FALSE
_HESSDONE=FALSE
_INTDONE=TRUE
_SCFDONE=TRUE
_MODUL_BLOCK=FALSE
_MODUL_CUDA=FALSE
_MODUL_SLATER=FALSE
_MODUL_MRCC=FALSE
_MODUL_NBO6=FALSE
_MODUL_NECI=TRUE
_MODUL_AIMS=TRUE
_MRCC_EXEC=
_FITC_AO_SAVED=FALSE
_FITC_MO_SAVED=FALSE
_SHARED_FS=TRUE
_LSTYP=SEWARD
_INTYP=INTS
_GEOMTYP=ZMAT
_GRADTYP=ALASKA
_DIRECT=FALSE
_DKHO= -1.000000000000000    
_SYNCM=  0.000000000000000    
_BASIS=AUG-CC-PVTZ
_ZORIENT=  0.000000000000000    
_NELEC=  10.00000000000000    
!SPIN=  0.000000000000000    
_QSDSTEP=  0.000000000000000    
_QSDIRC=  0.000000000000000    
_PROGRAM=RHF-SCF
_CPUSTEP= 0.2000000000000002    
_SYSSTEP= 0.4000000000000004E-01
_WALLSTEP= 0.3900000000000000    
!DFSCF=  0.000000000000000    
!SCSGRD=  0.000000000000000    
_BASINP=  610.0000000000000    
_CPUTOT=  1.600000000000000    
_CPUSORT= 0.2100000000000000    
_SYSSORT= 0.3000000000000003E-01
_WALLSORT= 0.3200000002980232    
_DFTEXFAC=  1.000000000000000    
_DMX=  0.000000000000000    
_DMY=  0.000000000000000    
_DMZ= 0.7630238919693926    
_DMX_SCF=  0.000000000000000    
_DMY_SCF=  0.000000000000000    
_DMZ_SCF= 0.7630238919693926    
_EHOMO=-0.5112368090014537    
_ELUMO= 0.2975373354087893E-01
_EIGS= -20.56350049329804    
_ENERGY= -76.06120311938969    
_ENERGY_METHOD=RHF
_ENERGY_BASIS=aug-cc-pVTZ
_GEOMETRY_METHOD=
_GEOMETRY_BASIS=
_ENUC=  9.348802247698661    
_GRADEXFAC=  9999.000000000000    
_GRADMETHOD=  1.000000000000000    
_NMRMETHOD=  0.000000000000000    
_NMRMAGNET=  0.000000000000000    
!GRID_FREEZE= -1.000000000000000    
_ITERATIONS=  9.000000000000000    
_LASTNELEC=  10.00000000000000    
_LASTSPIN=  0.000000000000000    
_LASTSYM=  1.000000000000000    
_MPP_PROG=  1.000000000000000    
_MSNSTATES=  0.000000000000000    
_RS2PHASE=  0.000000000000000    
_NPROC_MPP=  23.00000000000000    
_NPROC_MPPX=  23.00000000000000    
_NPROC_SMP=  1.000000000000000    
_NUMSTEP=  0.000000000000000    
_ORBITAL=  2100.200000000000    
_PI=  3.141592653589793    
_SEIG_MIN= 0.3697027323475132E-03
_SEWPROP=TRUE
_STATUS=  1.000000000000000    
_SYSTOT= 0.1900000000000001    
_VERSION=  2015001.000000000    
_WALLTOT=  3.040000000000000    
_DATE=11-Apr-20
_LASTORB=RHF
_MACHINE= 64 bit mpp version
_OUTPUT=/global/cscratch1/sd/rbello/Quantum_Chem/molpro.xml
_PGROUP=C2v
_TIME=13:36:56
_LIBMOL=/global/common/cori/software/molpro/2015/molprop_2015_1_linux_x86_64_i8/lib/
_VIGRDC=  0.000000000000000    
!VIBCNT=  0.000000000000000    
!RGHFCNT=  0.000000000000000    
!SURFREC=  0.000000000000000    
!ROTREC=  0.000000000000000    
!POLYREC=  0.000000000000000    
!DIPREC=  0.000000000000000    
!DIP4DREC=  0.000000000000000    
!DIPROT=  0.000000000000000    
!DIP4DROT=  0.000000000000000    
!PTREC=  0.000000000000000    
!PT4DREC=  0.000000000000000    
!VSCFREC=  0.000000000000000    
!VCIREC=  0.000000000000000    
!PVCIREC=  0.000000000000000    
!VMP2REC=  0.000000000000000    
!VMCSCFREC=  0.000000000000000    
!VMRCIREC=  0.000000000000000    
!VIBSTATEREC=  0.000000000000000    
!VIBSTATECNT=  0.000000000000000    
!VIBINFO=  0.000000000000000    
!GAREC=  0.000000000000000    
!SCFORB=  21002.00000000000    
!NEWMOL= -1.000000000000000    
!NEWSYM= -1.000000000000000    
_SLFILES=slscratch
_NGSSTO=  9.000000000000000    
_SIN=SIN
_COS=COS
_TAN=TAN
_ACOS=ACOS
_ASIN=ASIN
_ATAN=ATAN
_COSH=COSH
_SINH=SINH
_TANH=TANH
_ABS=ABS
_MOD=MOD
_ERF=ERF
_REFC=REFC
_ERFC=ERFC
_HYPOT=HYPOT
_J0=J0
_J1=J1
_JN=JN
_GAMMA=GAMMA
_LGAMMA=LGAMMA
_Y0=Y0
_Y1=Y1
_YN=YN
_EXP=EXP
_LOG=LOG
_LOG10=LOG10
_SQRT=SQRT
_INT=INT
_NINT=NINT
_MAX=MAX
_MIN=MIN
_COSMO=  0.000000000000000    
_COSMOIT=  0.000000000000000    
_COSMOES=  0.000000000000000    
_COSMOEDS=  0.000000000000000    
_COSMOEC=  0.000000000000000    
_COSMOEDCORR=  0.000000000000000    
_FEPSI=  1.000000000000000    
_SL_IsMM=  0.000000000000000    
_SL_NSYM=  4.000000000000000    
_SL_System_BitSw=  0.000000000000000    
_SL_Unique_atoms=  0.000000000000000    
_SL_GRAD=  0.000000000000000    
_SL_MAXUPD_Hess=  5.000000000000000    
_SL_N_PRINT_COD=  5.000000000000000    
_SL_PRINT_CODES=  0.000000000000000    
_SL_BasType=  0.000000000000000    
_SL_Energy_Pred=  0.000000000000000    
_SL_New_Coords=  0.000000000000000    
_SL_Total_Nuclea=  0.000000000000000    
_SL_Highest_Mltp=  0.000000000000000    
_SL_Ref_Geom=  0.000000000000000    
_SL_Symmetry_ope=  1.000000000000000    
_SL_agrad=  0.000000000000000    
_SL_GrdMax=  0.000000000000000    
_SL_GrdNorm=  0.000000000000000    
_SL_GrdRMS=  0.000000000000000    
_SL_Hss_Q=  0.000000000000000    
_SL_Hss_X=  0.000000000000000    
_SL_BMxOld=  0.000000000000000    
_SL_KtB=  0.000000000000000    
_SL_TROld=  0.000000000000000    
_SL_No_of_Intern=  0.000000000000000    
_SL_Hess=  0.000000000000000    
_SL_K=  0.000000000000000    
!LATTICE= -1.000000000000000    
!NEWLATTICE=  0.000000000000000    
!LATGRAD_VAR=FALSE
!SEW_LATTICE=  1.000000000000000    
!LOCAL=  0.000000000000000    
!SAVEDOM= -1.000000000000000    
!RESTDOM= -1.000000000000000    
!SAVEDOM_HF= -1.000000000000000    
!RESTDOM_HF= -1.000000000000000    
!HESSREC=  0.000000000000000    
!FREQREC=  0.000000000000000    
!NMODREC=  0.000000000000000    
!GTASKS=  0.000000000000000    
!HTASKS=  0.000000000000000    
!SAVEDOM_EOM= -1.000000000000000    
!RESTDOM_EOM= -1.000000000000000    
!GRADSTATE= -1.000000000000000    
!THRCHG= 0.1000000000000000    
!DEBUG= -1.000000000000000    
!CFIT_CPHF=  0.000000000000000    
!RDOMAUX_CPHF=  3.000000000000000    
!THRAO_CPHF= 0.1000000000000000E-09
!THRMO_CPHF= 0.1000000000000000E-08
!THROV_CPHF= 0.1000000000000000E-11
!THRSW_CPHF= 0.1000000000000000E-09
!THRPROD_CPHF= 0.1000000000000000E-08
!THRAOPR_CPHF= 0.1000000000000000E-11
!CFIT_SCFGRD=  0.000000000000000    
!RDOMAUX_SCFGRD=  5.000000000000000    
!THRAO_SCFGRD= 0.1000000000000000E-09
!THRMO_SCFGRD= 0.1000000000000000E-08
!THROV_SCFGRD= 0.1000000000000000E-11
!THRSW_SCFGRD= 0.1000000000000000E-09
!THRPROD_SCFGRD= 0.1000000000000000E-08
!THRAOPR_SCFGRD= 0.1000000000000000E-11
!LOCFIT_SCF=  0.000000000000000    
!LOCFIT_MP2= -1.000000000000000    
_RIDOM=  0.000000000000000    
!CC2_METHOD=  0.000000000000000    
_BASIS2006=FALSE
_SVDDEL= -1.000000000000000    
_SVDDELA= -1.000000000000000    
_SVDDELP= -1.000000000000000    
_SVDDELF= -1.000000000000000    
_SVDDELS= -1.000000000000000    
_SVDDEL_ABS= -1.000000000000000    
_SVDDELA_ABS= -1.000000000000000    
_SVDDELP_ABS= -1.000000000000000    
_SVDDELF_ABS= -1.000000000000000    
_SVDDELS_ABS= -1.000000000000000    
_MAXBASIS=  0.000000000000000    
!OPT_CONICAL=  0.000000000000000    
!CLEARSP_JGRID=  0.000000000000000    
_GRDHYBR=  0.000000000000000    
_STATEGRAD=  1.000000000000000    
_4EXT_NDISKS=  1.000000000000000    
!ZMP=  0.000000000000000    
_MAXIT_ZMP=  500.0000000000000    
_MAXDIS_ZMP=  100.0000000000000    
_ACCU_ZMP=  14.00000000000000    
_SHIFTA_ZMP= -100.0000000000000    
!EMBEDFLAG=  1.000000000000000    
!EMBED=FALSE
!EMBED_F12=FALSE
!EMBEDNUC=  0.000000000000000    
_EMBEDENERGY=  0.000000000000000    
_KSPACETIME=  0.000000000000000    
_RSPACETIME=  0.000000000000000    
!EMBED_DFC=FALSE
!NUM_VOIDS=  0.000000000000000    
_IBODY=  0.000000000000000    
_EMBE_TOTAL=  0.000000000000000    
_EMBE_HF=  0.000000000000000    
_EMBE_CORR=  0.000000000000000    
!EMBED_PROJ=FALSE
!EMBED_TRUNC=  0.000000000000000    
!EMB_PROJ_ZMU=  1000000.000000000    
!CORRECTION=  0.000000000000000    
!CORRECTION_HF=  0.000000000000000    
!EMBED_ENERGY=  0.000000000000000    
!EMBED_NAXC=FALSE
!EMBED_AORB=  0.000000000000000    
!EMBED_NACORR=  0.000000000000000    
!EMBED_MP2=FALSE
!EMBED_TRUNC_PERTURBATION=FALSE
!EMBED_FROZEN=  0.000000000000000    
_CHANGE_BASIS=FALSE
_RESTORE_BASIS=FALSE
_FIX_EMBED_GUESS=FALSE
!EDFT=  0.000000000000000    
_IFASTLATGRAD=  0.000000000000000    
_SINDEX=  0.000000000000000    
_AVDOM_OSV=  0.000000000000000    
_AVDOM_PNO=  0.000000000000000    
_AVDOM_PAO=  0.000000000000000    
_AVDOM_LMO=  0.000000000000000    
_CC2OSV_FLAG=  0.000000000000000    
_TMADC2_FLAG=FALSE
_PROPADC2_FLAG=FALSE
_LEN_VirQ=  0.000000000000000    
_GRDCC2LR_FLAG=FALSE
_GRDADC2_FLAG=FALSE
R=  0.000000000000000    
AHOH=  104.4776000000000    
GX1=  0.000000000000000    
GY1=  0.000000000000000    
GZ1=  0.000000000000000    
GX2=  0.000000000000000    
GY2= 0.7530886081000000    
GZ2= 0.5642560353000000    
GX3=  0.000000000000000    
GY3=-0.7530886081000000    
GZ3= 0.5642560353000000    
ACCU=  13.00000000000000    
NITORT=  1.000000000000000    
[Atoms] Angs
O     1    8         0.0000000000        0.0000000000        0.0000000000
H     2    1         0.0000000000        0.7530886081        0.5642560353
H     3    1         0.0000000000       -0.7530886081        0.5642560353
[GTO]
   1 0
 s   10  1.00
  0.1533000000D+05  0.5079996682D-03
  0.2299000000D+04  0.3928997434D-02
  0.5224000000D+03  0.2024298678D-01
  0.1473000000D+03  0.7918094828D-01
  0.4755000000D+02  0.2306868493D+00
  0.1676000000D+02  0.4331177171D+00
  0.6207000000D+01  0.3502597712D+00
  0.1752000000D+01  0.4272797209D-01
  0.6882000000D+00 -0.8153994674D-02
  0.2384000000D+00  0.2380998445D-02
 s   10  1.00
  0.1533000000D+05 -0.1150000604D-03
  0.2299000000D+04 -0.8950004697D-03
  0.5224000000D+03 -0.4636002433D-02
  0.1473000000D+03 -0.1872400983D-01
  0.4755000000D+02 -0.5846303068D-01
  0.1676000000D+02 -0.1364630716D+00
  0.6207000000D+01 -0.1757400922D+00
  0.1752000000D+01  0.1609340845D+00
  0.6882000000D+00  0.6034183167D+00
  0.2384000000D+00  0.3787651988D+00
 s   10  1.00
  0.1533000000D+05  0.0000000000D+00
  0.2299000000D+04  0.0000000000D+00
  0.5224000000D+03  0.0000000000D+00
  0.1473000000D+03  0.0000000000D+00
  0.4755000000D+02  0.0000000000D+00
  0.1676000000D+02  0.0000000000D+00
  0.6207000000D+01  0.0000000000D+00
  0.1752000000D+01  0.1000000000D+01
  0.6882000000D+00  0.0000000000D+00
  0.2384000000D+00  0.0000000000D+00
 s   10  1.00
  0.1533000000D+05  0.0000000000D+00
  0.2299000000D+04  0.0000000000D+00
  0.5224000000D+03  0.0000000000D+00
  0.1473000000D+03  0.0000000000D+00
  0.4755000000D+02  0.0000000000D+00
  0.1676000000D+02  0.0000000000D+00
  0.6207000000D+01  0.0000000000D+00
  0.1752000000D+01  0.0000000000D+00
  0.6882000000D+00  0.0000000000D+00
  0.2384000000D+00  0.1000000000D+01
 s    1  1.00
  0.7376000000D-01  0.1000000000D+01
 p    5  1.00
  0.3446000000D+02  0.1592799074D-01
  0.7749000000D+01  0.9973994203D-01
  0.2280000000D+01  0.3104918195D+00
  0.7156000000D+00  0.4910257146D+00
  0.2140000000D+00  0.3363368045D+00
 p    5  1.00
  0.3446000000D+02  0.0000000000D+00
  0.7749000000D+01  0.0000000000D+00
  0.2280000000D+01  0.0000000000D+00
  0.7156000000D+00  0.1000000000D+01
  0.2140000000D+00  0.0000000000D+00
 p    5  1.00
  0.3446000000D+02  0.0000000000D+00
  0.7749000000D+01  0.0000000000D+00
  0.2280000000D+01  0.0000000000D+00
  0.7156000000D+00  0.0000000000D+00
  0.2140000000D+00  0.1000000000D+01
 p    1  1.00
  0.5974000000D-01  0.1000000000D+01
 d    1  1.00
  0.2314000000D+01  0.1000000000D+01
 d    1  1.00
  0.6450000000D+00  0.1000000000D+01
 d    1  1.00
  0.2140000000D+00  0.1000000000D+01
 f    1  1.00
  0.1428000000D+01  0.1000000000D+01
 f    1  1.00
  0.5000000000D+00  0.1000000000D+01
  
   2 0
 s    5  1.00
  0.3387000000D+02  0.6067999217D-02
  0.5095000000D+01  0.4530799416D-01
  0.1159000000D+01  0.2028219738D+00
  0.3258000000D+00  0.5039029350D+00
  0.1027000000D+00  0.3834209505D+00
 s    5  1.00
  0.3387000000D+02  0.0000000000D+00
  0.5095000000D+01  0.0000000000D+00
  0.1159000000D+01  0.0000000000D+00
  0.3258000000D+00  0.1000000000D+01
  0.1027000000D+00  0.0000000000D+00
 s    5  1.00
  0.3387000000D+02  0.0000000000D+00
  0.5095000000D+01  0.0000000000D+00
  0.1159000000D+01  0.0000000000D+00
  0.3258000000D+00  0.0000000000D+00
  0.1027000000D+00  0.1000000000D+01
 s    1  1.00
  0.2526000000D-01  0.1000000000D+01
 p    1  1.00
  0.1407000000D+01  0.1000000000D+01
 p    1  1.00
  0.3880000000D+00  0.1000000000D+01
 p    1  1.00
  0.1020000000D+00  0.1000000000D+01
 d    1  1.00
  0.1057000000D+01  0.1000000000D+01
 d    1  1.00
  0.2470000000D+00  0.1000000000D+01
  
   3 0
 s    5  1.00
  0.3387000000D+02  0.6067999217D-02
  0.5095000000D+01  0.4530799416D-01
  0.1159000000D+01  0.2028219738D+00
  0.3258000000D+00  0.5039029350D+00
  0.1027000000D+00  0.3834209505D+00
 s    5  1.00
  0.3387000000D+02  0.0000000000D+00
  0.5095000000D+01  0.0000000000D+00
  0.1159000000D+01  0.0000000000D+00
  0.3258000000D+00  0.1000000000D+01
  0.1027000000D+00  0.0000000000D+00
 s    5  1.00
  0.3387000000D+02  0.0000000000D+00
  0.5095000000D+01  0.0000000000D+00
  0.1159000000D+01  0.0000000000D+00
  0.3258000000D+00  0.0000000000D+00
  0.1027000000D+00  0.1000000000D+01
 s    1  1.00
  0.2526000000D-01  0.1000000000D+01
 p    1  1.00
  0.1407000000D+01  0.1000000000D+01
 p    1  1.00
  0.3880000000D+00  0.1000000000D+01
 p    1  1.00
  0.1020000000D+00  0.1000000000D+01
 d    1  1.00
  0.1057000000D+01  0.1000000000D+01
 d    1  1.00
  0.2470000000D+00  0.1000000000D+01
 
 
[MO]
 Sym=      1.1
 Ene=     -20.5635
 Spin= Alpha
 Occup=    2.000000
1 0.99886977633685
2 -0.002215397472811
3 0.001339812894581
4 -0.000004180768445
5 0.000548838632543
6 0.0
7 0.0
8 0.004778581946589
9 0.0
10 0.0
11 -0.003730531833399
12 0.0
13 0.0
14 -0.001157169841262
15 0.0
16 0.0
17 0.000185654641842
18 -0.000090895245319
19 0.000082587393316
20 0.000008307852004
21 0.0
22 0.0
23 0.0
24 0.000444705577625
25 -0.000386073005962
26 -0.000058632571663
27 0.0
28 0.0
29 0.0
30 -0.000178445813651
31 0.000109582826994
32 0.000068862986658
33 0.0
34 0.0
35 0.0
36 0.0
37 0.0
38 -0.000039290663317
39 0.0
40 0.0
41 -0.000009119140879
42 0.0
43 0.0
44 0.000061833097313
45 0.0
46 0.0
47 0.0
48 0.000101391442167
49 0.0
50 0.0
51 0.000087807533700
52 0.0
53 0.0
54 -0.000223838427914
55 0.0
56 0.002239240169404
57 -0.000535094559902
58 -0.001276546316515
59 0.000012380675065
60 0.0
61 -0.000102597933280
62 -0.000055538548035
63 0.0
64 -0.000530661889263
65 -0.000462529931180
66 0.0
67 -0.000076124646814
68 -0.000038598432129
69 0.000102705643914
70 -0.000063087655025
71 -0.000039617988889
72 0.0
73 0.0
74 -0.000189205570701
75 -0.000216447626108
76 0.000193585960579
77 0.000022861665528
78 0.0
79 0.0
80 0.000379059881317
81 0.002239240169404
82 -0.000535094559902
83 -0.001276546316515
84 0.000012380675065
85 0.0
86 0.000102597933280
87 -0.000055538548035
88 0.0
89 0.000530661889263
90 -0.000462529931180
91 0.0
92 0.000076124646814
93 -0.000038598432129
94 0.000102705643914
95 -0.000063087655025
96 -0.000039617988889
97 0.0
98 0.0
99 0.000189205570701
100 -0.000216447626108
101 0.000193585960579
102 0.000022861665528
103 0.0
104 0.0
105 -0.000379059881317


主要区别是文件2有[Molpro variables]部分。

我对文件1的输出(注意:预期/期望输出):

O    1    8         0.000000000000       0.000000000000      -0.124302651265
H    2    1         0.000000000000      -1.424704710000       0.986386639735
H    3    1        -0.000000000000       1.424704710000       0.986386639735

O    1    8         0.000000000000       0.000000000000      -0.124302651265
H    2    1         0.000000000000      -1.424704710000       0.986386639735
H    3    1        -0.000000000000       1.424704710000       0.986386639735
Atoms] Angs
O    1    8         0.000000000000       0.000000000000      -0.124302651265
H    2    1         0.000000000000      -1.424704710000       0.986386639735
H    3    1        -0.000000000000       1.424704710000       0.986386639735

共有1个答案

韩刚洁
2023-03-14

这里有一个问题:

if (line.find("Molpro") != std::string::npos) {
    std::getline(source, line, '['); // reads until [
}
if (line.find("Atoms") != std::string::npos) {

file2中,一旦读取molpro,您将提取所有内容,直到下一次[]并覆盖。在while循环的当前迭代中,搜索atoms失败(这是应该的),但随后检查字符串mo,该字符串确实存在于文件中(并导致跳过文件中剩余的所有内容)。这也导致跳过正在查找的atoms字符串。

只需添加continue,如下所示:

if (line.find("Molpro") != std::string::npos) {
    std::getline(source, line, '['); // reads until [
    continue; // <-- here
}
if (line.find("Atoms") != std::string::npos) {
O     1    8         0.0000000000        0.0000000000        0.0000000000
H     2    1         0.0000000000        0.7530886081        0.5642560353
H     3    1         0.0000000000       -0.7530886081        0.5642560353

这似乎是正确的。

坦率地说,我不知道为什么执行查找(toms)会生成它所做的输出;我的猜测是,这与File2中出现的几十次mo有关。不管怎么说,错误的影响并不太重要,一旦发现了错误。

我建议考虑一下您的代码是如何结构化的。您可能希望分支是互斥的,在这种情况下,您应该为您要查找的每个字符串嵌套if-else语句。

 类似资料:
  • 我有一个程序可以读取两个文件(“incompleta.txt”和“completa.txt”),并比较两个文件中是否有相同的名称。其工作原理如下: 它将“completa.txt”中的所有名称存储在ArrayList中 问题是我的“lista.txt”看起来像这样:Image 第二条线完全是混乱和扭曲的。 我的Java代码:

  • 问题内容: 试图在LINQ查询(使用Entityframework)中实现条件创建了奇怪的查询。在某些情况下,即使阈值设置为180秒,这些查询也会超时: 使用一些不太优雅的if语句,我没有任何问题,查询在几秒钟内返回: 条件语句都是从查询字符串传递的,这就是为什么它们有时可能带有值而有时却没有值的原因。 使用三元运算符时会出现相同的问题 关于这些内联条件为何表现如此差的情况,是否有合理的解释? 问

  • 问题内容: 我从VOC2012数据集中获取了以下png文件。 我使用以下简单代码: 它产生了以下图像: 奇怪的是,结果不是原始图像的灰度图像。上面的代码还用于deeplab张量流数据集中,以删除真实图像中的颜色图。 有人知道为什么吗?非常感谢! 问题答案: 问题是您的图像已泛化。因此,没有为每个像素存储完整的RGB三元组,而是有一个256个RGB三元组的列表,然后在每个像素位置将索引存储到列表中-

  • 问题内容: 因此,当我在Java中使用Doubles进行加法或减法时,它会给我带来奇怪的结果。这里有一些: 如果我加上,它给了我。没错 如果我添加,它会给我(重复s 的数量可能会关闭)。错了 如果我减去,它就会给我(再次,重复的s可能会关闭)。错了 起初我以为这只是将双精度数与十进制值相加的问题,但我错了。以下工作正常: 现在,添加的第一个数字是保存为变量的双精度数,尽管第二个变量从捕获文本。例如

  • 我正在写一个程序: 打开excel文件 根据下面的代码片段,我可以成功地写下公式,检查excel文件将得到正确的总和。 可悲的是,当我读到公式的值时,它应该是“101.0”,它给了我一个“0.0”。 我尝试了通过微软电子表格应用程序编写一个公式来比较程序读取时返回的值。结果,对于我的程序编写的公式,它是同一个不正确的值,但是对于使用微软电子表格编写的公式,这个值被完美地读取了。 我错过了什么?为什

  • 这是最奇怪的错误,我甚至不知道从哪里开始理解错在哪里。 S3一直工作得很好,直到突然有一天(昨天)它奇怪地编码任何上传给奇怪字符的文本文件。每当一个文本文件中有`、`、Ω或任何其他UTF-8可比字符,但没有英文字符时,该文本文件就会被弄乱。我尝试过使用各种客户端以及AWS的web界面上传。上传很顺利,然后我下载文件,它搞砸了。我试着把它下载到我的Mac上,我试着把它下载到带有Linux的覆盆子上。