计算化学公社
标题:
Multiwfn免环境变量加载配置文件settings.ini
[打印本页]
作者Author:
slxc920113
时间:
2019-10-16 16:56
标题:
Multiwfn免环境变量加载配置文件settings.ini
本帖最后由 slxc920113 于 2019-10-16 17:05 编辑
Linux系统从命令行直接执行Multiwfn,或者在window中直接将文件拖到Multiwfn.exe程序文件上打开的时候,由于程序的启动路径是当前shell或文件所在路径,在
相对路径
下无法找到settings.ini配置文件,这个时候就会导致程序使用默认的配置参数,某些功能(比如用cubegen加速表面静电势的计算)会失效。
Multiwfn的源码fileIO.f90中加载settings.ini的代码如下:
inquire(file="settings.ini",exist=alive)
if (alive==.true.) then
settingpath="settings.ini"
else if (alive==.false.) then
call getenv("Multiwfnpath",c80tmp)
if (isys==1) then
settingpath=trim(c80tmp)//"\settings.ini"
else if (isys==2) then
settingpath=trim(c80tmp)//"/settings.ini"
end if
inquire(file=settingpath,exist=alive)
if (alive==.false.) then
write(*,"(a)") " Warning: ""settings.ini"" was found neither in current folder nor in the path defined by ""Multiwfnpath"" &
environment variable. Now using default settings instead"
write(*,*)
return
end if
end if
复制代码
假设程序安装在/opt/software/Multiwfn路径下
Linux系统下,可以添加Multiwfnpath这个环境变量来解决问题
export Multiwfnpath=/opt/software/Multiwfn
复制代码
window下也可以添加
Multiwfnpath
环境变量,或者用一个更加简单的方法吗,创建一个快捷方式。
右击快捷方式>属性,然后将起始位置改成settings.ini所在的路径(默认)
但是,这又会带来一个问题,输出各种数据文件的时候,都会保存在程序所在路径,非常不方便。
真正一劳永逸的方法:直接修改源代码。
程序执行参数中第一个参数就是程序自身所在的路径,所以只需要从Multiwfn所在的
绝对路径
加载settings.ini就能解决这个问题
将上面那段代码稍作修改
inquire(file="settings.ini",exist=alive)
if (alive==.true.) then
settingpath="settings.ini"
else if (alive==.false.) then
call getenv("Multiwfnpath",c80tmp)
if (isys==1) then
settingpath=trim(c80tmp)//"\settings.ini"
else if (isys==2) then
settingpath=trim(c80tmp)//"/settings.ini"
end if
inquire(file=settingpath,exist=alive)
if (alive==.false.) then
!get prigram path of Multiwfn
call getarg(0,c80tmp)
if (isys==1) then
!replace window path of Multiwfn.exe with settings.ini
settingpath=c80tmp(:index(c80tmp,'\',.true.))//"settings.ini"
else if (isys==2) then
!replace *nix path of Multiwfn with settings.ini
settingpath=c80tmp(:index(c80tmp,'/',.true.))//"settings.ini"
end if
inquire(file=settingpath,exist=alive)
if (alive==.false.) then
write(*,"(a)") " Warning: ""settings.ini"" was found neither in current folder nor in the path defined by ""Multiwfnpath"" &
environment variable. Now using default settings instead"
write(*,*)
return
end if
end if
end if
复制代码
重新编译源码即可。
作者Author:
march_happy
时间:
2020-6-21 17:22
补充一下,事实上 Windows 里也能设置 Multiwfnpath 环境变量。直接在搜索框里打“高级系统设置”(Advanced System Settings)打开设置窗口:
(, 下载次数 Times of downloads: 75)
上传 Uploaded
点击下载Click to download
在“高级”选项卡里有环境变量的选项。
(, 下载次数 Times of downloads: 60)
上传 Uploaded
点击下载Click to download
建议作为用户环境变量设置。如果是使用你自己写的 Powershell 脚本的话可以参考微软相关的文档:
https://docs.microsoft.com/en-us ... view=powershell-5.1
欢迎光临 计算化学公社 (http://bbs.keinsci.com/)
Powered by Discuz! X3.3