wfn=*.fchk
core=12

[grid]
%process
    electron
    esp
%command
#!/bin/bash
    mkdir -p ${input}_ESP
    mv density.cub ${input}_ESP/${input}_den.cub
    mv totesp.cub ${input}_ESP/${input}_esp.cub
    mv ${output} ${input}_ESP
end

[surface]
%process
    espext
%command
#!/bin/bash
    mv vtx.pdb ${input}_ESP/vtx1.pdb
    mv mol.pdb ${input}_ESP/mol1.pdb

    unit=$(grep "REMARK.*Unit of B-factor field" surfanalysis.pdb | awk '{print $NF}')
    if [ -z "$unit" ]; then unit="unknown"; fi
    printf "%5s %6s %4s %15s\n" "index" "serial" "type" "Unit($unit)" > index.txt
    index=0; while IFS= read -r line; do
        if [[ $line =~ ^HETATM ]]; then
            serial=$(echo "$line" | awk '{print $2}')      # 第2列：原子编号
            type=$(echo "$line" | awk '{print $3}')        # 第3列：原子类型
            value=$(echo "$line" | cut -c61-66 | awk '{print $1}')  # 第11列：B-factor值（固定位置61-66）
            printf "%5d %6d %4s %8s\n" "$index" "$serial" "$type" "$value" >> index.txt
            ((index++))
        fi
    done < surfanalysis.pdb

    mv index.txt *.out surfanalysis.pdb ${input}_ESP

    cat << EOF > ${input}_ESP/esp.bat
    vmd -e esp.vmd
EOF

    cat << EOF2 > ${input}_ESP/esp.vmd
    vcube *_den.cub map *_esp.cub
    set colorlow -20
    set colorhigh 20
    mol scaleminmax 0 1 -20 20
    puts "unit: kcal/mol"
    
    mol new surfanalysis.pdb
    mol modstyle 0 top VDW 0.07 20
    mol modselect 0 top name C
    mol modcolor 0 top ColorID 32
    mol addrep top
    mol modstyle 1 top VDW 0.07 20
    mol modselect 1 top name O
    mol modcolor 1 top ColorID 21
EOF2

end

%command
cd ${input}_ESP
vmd -e esp.vmd
end

# Bundled by bane dysta
# ConfDir: D:\MyProgram\banewfn\conf

#>>> BANEWFN_INLINE_CONF_BEGIN grid
## bundled module: grid
# # 主逻辑
# [main]
# 5
# 
# # define
# [wfn2]
# 0
# 1
# ${operator}
# 
# # density.cub
# [electron]
# 1
# ${grid:-3}
# 2
# 0
# 5
# 
# # spindensity.cub
# [spin]
# 5
# ${grid:-2}
# 2
# 0
# 5
# 
# # ELF.cub
# [elf]
# 9
# ${grid:-3}
# 2
# 0
# 5
# 
# # LOL.cub
# [lol]
# 10
# ${grid:-3}
# 2
# 0
# 5
# 
# # totesp.cub 
# # 注意：由于需要切换cub文件，esp必须作为最后一个处理步骤使用
# [esp]
# 12
# ${grid:-1}
# 2
# 0
# r
# totesp.cub
# 13
# 11
# 5
# 627.51
# 0
# totesp.cub
# -1
# 5
# 
# # avglocion
# [alie]
# 18
# ${grid:-3}
# 2
# 0
# 5
# 
# [leae]
# -10
# 1000
# 2
# -27
# 5
# 100
# ${grid:-3}
# 2
# 0
# 5
# 
# # 退出
# [quit]
# -10
# q
#<<< BANEWFN_INLINE_CONF_END grid

#>>> BANEWFN_INLINE_CONF_BEGIN surface
## bundled module: surface
# [main]
# 12
# 
# [espext]
# 3
# 0.15
# 0
# 5
# mol.pdb
# 6
# 2
# -1
# -1
# 12
# 
# # surfanalysis.pdb
# [alieext]
# 1               # Select the way to define surface
# 1               #  Isosurface of electron density
# ${iso:-0.0005}          
# 2               # Select mapped function
# 2               # Average local ionization energy (ESP)
# 0
# 2
# -1
# -1
# 12
# 
# [leaeext]
# 1               # Select the way to define surface
# 1               #  Isosurface of electron density
# ${iso:-0.004}          
# 2               # Select mapped function
# -4               # Local electron attachment energy (LEAE)
# 0
# 2
# -1
# -1
# 12
# 
# [quit]
# -1
# q
#<<< BANEWFN_INLINE_CONF_END surface

