计算化学公社

 找回密码 Forget password
 注册 Register
Views: 6674|回复 Reply: 1
打印 Print 上一主题 Last thread 下一主题 Next thread

[其它] Multiwfn免环境变量加载配置文件settings.ini

[复制链接 Copy URL]

320

帖子

0

威望

1485

eV
积分
1805

Level 5 (御坂)

本帖最后由 slxc920113 于 2019-10-16 17:05 编辑

Linux系统从命令行直接执行Multiwfn,或者在window中直接将文件拖到Multiwfn.exe程序文件上打开的时候,由于程序的启动路径是当前shell或文件所在路径,在相对路径下无法找到settings.ini配置文件,这个时候就会导致程序使用默认的配置参数,某些功能(比如用cubegen加速表面静电势的计算)会失效。
Multiwfn的源码fileIO.f90中加载settings.ini的代码如下:
  1. inquire(file="settings.ini",exist=alive)
  2. if (alive==.true.) then
  3.         settingpath="settings.ini"
  4. else if (alive==.false.) then
  5.         call getenv("Multiwfnpath",c80tmp)
  6.         if (isys==1) then
  7.                 settingpath=trim(c80tmp)//"\settings.ini"
  8.         else if (isys==2) then
  9.                 settingpath=trim(c80tmp)//"/settings.ini"
  10.         end if
  11.         inquire(file=settingpath,exist=alive)
  12.         if (alive==.false.) then
  13.                 write(*,"(a)") " Warning: ""settings.ini"" was found neither in current folder nor in the path defined by ""Multiwfnpath"" &
  14.                 environment variable. Now using default settings instead"
  15.                 write(*,*)
  16.                 return
  17.         end if
  18. end if
复制代码


假设程序安装在/opt/software/Multiwfn路径下
Linux系统下,可以添加Multiwfnpath这个环境变量来解决问题
  1. export Multiwfnpath=/opt/software/Multiwfn
复制代码

window下也可以添加Multiwfnpath环境变量,或者用一个更加简单的方法吗,创建一个快捷方式。
右击快捷方式>属性,然后将起始位置改成settings.ini所在的路径(默认)
但是,这又会带来一个问题,输出各种数据文件的时候,都会保存在程序所在路径,非常不方便。

真正一劳永逸的方法:直接修改源代码。
程序执行参数中第一个参数就是程序自身所在的路径,所以只需要从Multiwfn所在的绝对路径加载settings.ini就能解决这个问题
将上面那段代码稍作修改
  1. inquire(file="settings.ini",exist=alive)
  2. if (alive==.true.) then
  3.         settingpath="settings.ini"
  4. else if (alive==.false.) then
  5.         call getenv("Multiwfnpath",c80tmp)
  6.         if (isys==1) then
  7.                 settingpath=trim(c80tmp)//"\settings.ini"
  8.         else if (isys==2) then
  9.                 settingpath=trim(c80tmp)//"/settings.ini"
  10.         end if
  11.         inquire(file=settingpath,exist=alive)
  12.         if (alive==.false.) then
  13.                 !get prigram path of Multiwfn
  14.                 call getarg(0,c80tmp)
  15.                 if (isys==1) then
  16.                         !replace window path of Multiwfn.exe with settings.ini
  17.                         settingpath=c80tmp(:index(c80tmp,'\',.true.))//"settings.ini"
  18.                 else if (isys==2) then
  19.                         !replace *nix path of Multiwfn with settings.ini
  20.                         settingpath=c80tmp(:index(c80tmp,'/',.true.))//"settings.ini"
  21.                 end if
  22.                 inquire(file=settingpath,exist=alive)
  23.                 if (alive==.false.) then
  24.                         write(*,"(a)") " Warning: ""settings.ini"" was found neither in current folder nor in the path defined by ""Multiwfnpath"" &
  25.                         environment variable. Now using default settings instead"
  26.                         write(*,*)
  27.                         return
  28.                 end if
  29.         end if
  30. end if
复制代码


重新编译源码即可。

评分 Rate

参与人数
Participants 1
eV +5 收起 理由
Reason
zsu007 + 5 好物!

查看全部评分 View all ratings

1

帖子

0

威望

29

eV
积分
30

Level 2 能力者

2#
发表于 Post on 2020-6-21 17:22:16 | 只看该作者 Only view this author
补充一下,事实上 Windows 里也能设置 Multiwfnpath 环境变量。直接在搜索框里打“高级系统设置”(Advanced System Settings)打开设置窗口:



在“高级”选项卡里有环境变量的选项。



建议作为用户环境变量设置。如果是使用你自己写的 Powershell 脚本的话可以参考微软相关的文档:

https://docs.microsoft.com/en-us ... view=powershell-5.1

本版积分规则 Credits rule

手机版 Mobile version|北京科音自然科学研究中心 Beijing Kein Research Center for Natural Sciences|京公网安备 11010502035419号|计算化学公社 — 北京科音旗下高水平计算化学交流论坛 ( 京ICP备14038949号-1 )|网站地图

GMT+8, 2025-8-18 05:10 , Processed in 0.180120 second(s), 30 queries , Gzip On.

快速回复 返回顶部 返回列表 Return to list