Class: VaspUtils::VaspDir

Inherits:
Comana::ComputationManager
  • Object
show all
Defined in:
lib/vasputils/vaspdir.rb

Overview

Class for VASP executable directory, including input and output files.

Defined Under Namespace

Classes: AlreadyExistError, ExecuteError, InitializeError, InvalidValueError, NoVaspBinaryError, PrepareNextError

Constant Summary collapse

MACHINEFILE =
"machines"

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ VaspDir

Returns a new instance of VaspDir.



26
27
28
29
30
31
32
33
# File 'lib/vasputils/vaspdir.rb', line 26

def initialize(dir)
  super(dir)
  @lockdir        = "lock_execute"
  %w(INCAR KPOINTS POSCAR POTCAR).each do |file|
    infile = "#{@dir}/#{file}"
    raise InitializeError, infile unless FileTest.exist? infile
  end
end

Instance Method Details

#contcarObject

配下の CONTCAR を CrystalCell::Cell インスタンスにして返す。存在しなければ例外 Errno::ENOENT を返す。



49
50
51
# File 'lib/vasputils/vaspdir.rb', line 49

def contcar
  VaspUtils::Poscar.load_file("#{@dir}/CONTCAR")
end

#finished?Boolean

正常に終了していれば true を返す。実行する前や実行中、OUTCAR が完遂していなければ false。MEMO: PI12345 ファイルは実行中のみ存在し、終了後 vasp (mpi?) に自動的に削除される。

Returns:

  • (Boolean)


74
75
76
77
78
79
80
# File 'lib/vasputils/vaspdir.rb', line 74

def finished?
  begin
    return VaspUtils::Outcar.load_file("#{@dir}/OUTCAR")[:normal_ended]
  rescue Errno::ENOENT
    return false
  end
end

#incarObject

配下の INCAR を表現する Incar クラスインスタンスを返す。存在しなければ例外 Errno::ENOENT を返す筈だが、vasp dir の判定を incar でやっているので生じる筈がない。



56
57
58
# File 'lib/vasputils/vaspdir.rb', line 56

def incar
  VaspUtils::Incar.load_file("#{@dir}/INCAR")
end

#kpointsObject

配下の KPOINTS を表現する Kpoints クラスインスタンスを返す。



61
62
63
# File 'lib/vasputils/vaspdir.rb', line 61

def kpoints
  VaspUtils::Kpoints.load_file("#{@dir}/KPOINTS")
end

#mutate(tgt_name, condition) ⇒ Object

‘tgt_name’ is a String. ‘conditions’ is a Hash.

E.g., {:encut => 500.0, :ka => 2, :kb => 4}

Raises:



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/vasputils/vaspdir.rb', line 129

def mutate(tgt_name, condition)
  raise AlreadyExistError, "Already exist: #{tgt_name}" if File.exist? tgt_name

  Dir.mkdir tgt_name

  ##POSCAR
  FileUtils.cp("#{@dir}/POSCAR", "#{tgt_name}/POSCAR")

  ##POTCAR
  FileUtils.cp("#{@dir}/POTCAR", "#{tgt_name}/POTCAR")

  ##INCAR
  new_incar = incar
  new_incar["ENCUT"] = condition[:encut] if condition[:encut]
  File.open("#{tgt_name}/INCAR", "w") do |io|
    new_incar.dump(io)
  end

  ##KPOINTS
  new_kpoints = kpoints
  new_kpoints.mesh[0] = condition[:ka] if condition[:ka]
  new_kpoints.mesh[1] = condition[:kb] if condition[:kb]
  new_kpoints.mesh[2] = condition[:kc] if condition[:kc]
  if condition[:kab]
    new_kpoints.mesh[0] = condition[:kab]
    new_kpoints.mesh[1] = condition[:kab]
  end
  if condition[:kbc]
    new_kpoints.mesh[1] = condition[:kbc]
    new_kpoints.mesh[2] = condition[:kbc]
  end
  if condition[:kca]
    new_kpoints.mesh[2] = condition[:kca]
    new_kpoints.mesh[0] = condition[:kca]
  end
  if condition[:kabc]
    new_kpoints.mesh[0] = condition[:kabc]
    new_kpoints.mesh[1] = condition[:kabc]
    new_kpoints.mesh[2] = condition[:kabc]
  end
  File.open("#{tgt_name}/KPOINTS", "w") do |io|
    new_kpoints.dump(io)
  end
end

#outcarObject

配下の OUTCAR を Outcar インスタンスにして返す。存在しなければ例外 Errno::ENOENT を返す。



37
38
39
# File 'lib/vasputils/vaspdir.rb', line 37

def outcar
  VaspUtils::Outcar.load_file("#{@dir}/OUTCAR")
end

#poscarObject

配下の POSCAR を CrystalCell::Cell インスタンスにして返す。存在しなければ例外 Errno::ENOENT を返す。



43
44
45
# File 'lib/vasputils/vaspdir.rb', line 43

def poscar
  VaspUtils::Poscar.load_file("#{@dir}/POSCAR")
end

#reset_clean(io = $stdout) ⇒ Object

VASP の出力ファイルを削除する。入力のみに使うもの、残す

INCAR KPOINTS POSCAR POTCAR

主に出力。消す。

CHG CHGCAR CONTCAR DOSCAR EIGENVAL EIGENVALUE ELFCAR
EXHCAR IBZKPT LOCPOT OSZICAR OUTCAR PCDAT PRJCAR PROCAR
PROOUT STOPCAR TMPCAR WAVECAR XDATCAR vasprun.xml

付随する出力ファイル。残す。

machines stderr stdout


92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/vasputils/vaspdir.rb', line 92

def reset_clean(io = $stdout)
  remove_files = %w(
    CHG CHGCAR CONTCAR DOSCAR EIGENVAL EIGENVALUE
    ELFCAR EXHCAR IBZKPT LOCPOT OSZICAR OUTCAR PCDAT
    PRJCAR PROCAR
    PROOUT STOPCAR TMPCAR WAVECAR XDATCAR vasprun.xml
  )
  remove_files.each do |file|
    io.puts "    Removing: #{file}"
    FileUtils.rm_rf "#{@dir}/#{file}"
  end
end

#reset_initialize(io = $stdout) ⇒ Object

Delete all except for four files, INCAR, KPOINTS, POSCAR, POTCAR.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/vasputils/vaspdir.rb', line 106

def reset_initialize(io = $stdout)
  keep_files   = ["INCAR", "KPOINTS", "POSCAR", "POTCAR"]
  remove_files = []
  Dir.entries( @dir ).sort.each do |file|
    next if file == "."
    next if file == ".."
    remove_files << file unless keep_files.include? file
  end

  if remove_files.size == 0
    io.puts "    No remove files."
    return
  else
    remove_files.each do |file|
      io.puts "    Removing: #{file}"
      FileUtils.rm_rf "#{@dir}/#{file}"
    end
  end
end

#vasprun_xmlObject

配下の vasprun.xml を表現する VasprunXml クラスインスタンスを返す。



66
67
68
# File 'lib/vasputils/vaspdir.rb', line 66

def vasprun_xml
  VaspUtils::VasprunXml.load_file("#{@dir}/vasprun.xml")
end