Class: VaspUtils::VaspGeometryOptimizer
- Inherits:
-
Comana::ComputationManager
- Object
- Comana::ComputationManager
- VaspUtils::VaspGeometryOptimizer
- Defined in:
- lib/vasputils/vaspgeometryoptimizer.rb
Overview
The directory must has subdirs whose name is started by ‘geomopt’. This restriction of naming is necessary to distinguish from simple aggregation of vasp directories.
Defined Under Namespace
Classes: InitializeError, LatestDirStartedError, NoContcarError, NoIntegerEndedNameError, NoVaspDirError
Constant Summary collapse
- PREFIX =
"geomopt"
Class Method Summary collapse
-
.next_name(name) ⇒ Object
Return incremented name.
Instance Method Summary collapse
-
#calculate ⇒ Object
注目した VaspDir が yet なら実行し、続ける。 yet 以外なら例外。 VaspDir になっているか。.
-
#finished? ⇒ Boolean
latest_dir から返って来る最新の VaspDir が finished? で真を返し、 かつ Iteration が 1 であるか。 Note: even when the geometry optimization does not include lattice shape, calculate will continued till to converge to Iter 1 calculation.
-
#initialize(dir) ⇒ VaspGeometryOptimizer
constructor
A new instance of VaspGeometryOptimizer.
-
#latest_dir ⇒ Object
Find latest VaspDir.
-
#reset_init ⇒ Object
Keep ‘geomopt00/POSCAR,POTCAR,INCAR,POTCAR’, remove others.
-
#reset_next(io = $stdout) ⇒ Object
Generate a new vaspdir as ‘geomopt00’.
-
#reset_reincarnate ⇒ Object
Generate a new vaspdir as ‘geomopt00’.
Constructor Details
#initialize(dir) ⇒ VaspGeometryOptimizer
29 30 31 32 33 34 35 36 37 |
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 29 def initialize(dir) super(dir) @lockdir = "lock_vaspgeomopt" begin latest_dir # to check. rescue NoVaspDirError raise InitializeError end end |
Class Method Details
.next_name(name) ⇒ Object
Return incremented name. If the name of VaspDir ends with string of integer, return incremental value with the basename. If not ended with integer, this method assume “00”
43 44 45 46 47 |
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 43 def self.next_name(name) basename = name.sub(/(\d*)$/, "") new_num = $1.to_i + 1 return basename + sprintf("%02d", new_num) end |
Instance Method Details
#calculate ⇒ Object
注目した VaspDir が yet なら実行し、続ける。yet 以外なら例外。VaspDir になっているか。
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 52 def calculate $stdout.puts "Calculate #{latest_dir.dir}" $stdout.flush latest_dir.start #dir = latest_dir #while (! finished?) # raise LatestDirStartedError if dir.state == :started # dir.start # if dir.finished? # break # else # #dir = prepare_next # puts "Geometry optimization fihished. Exit." # end #end #puts "Geometry optimization fihished. Exit." #sleep 1 # for interrupt end |
#finished? ⇒ Boolean
latest_dir から返って来る最新の VaspDir が finished? で真を返し、かつ Iteration が 1 であるか。Note: even when the geometry optimization does not include lattice shape,
calculate will continued till to converge to Iter 1 calculation.
76 77 78 79 80 |
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 76 def finished? return false unless latest_dir.finished? return false unless latest_dir.outcar[:ionic_steps] == 1 return true end |
#latest_dir ⇒ Object
Find latest VaspDir. Return a last VaspDir which has the name by name sort and which can be made as a VaspDir instance. Note: in a series of geometry optimization,
the directory names should have a rule of naming
which can define a method <=>.
Usually, it is simple sort of String.
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 89 def latest_dir Dir.glob("#{@dir}/#{PREFIX}*").sort.reverse.find do |dir| begin vd = VaspUtils::VaspDir.new(dir) return vd rescue VaspUtils::VaspDir::InitializeError next end end raise NoVaspDirError, @dir end |
#reset_init ⇒ Object
Keep ‘geomopt00/POSCAR,POTCAR,INCAR,POTCAR’, remove others.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 102 def reset_init poscars = Dir.glob("#{@dir}/#{PREFIX}*/POSCAR").sort poscar = nil path = nil poscars.each do |poscar| begin VaspUtils::Poscar.load_file poscar path = File.dirname(poscar) break rescue VaspUtils::Poscar::ParseError next end end raise NoVaspDirError unless path ##geomopt* rm_list = Dir.glob "#{@dir}/#{PREFIX}*" rm_list.delete path ##input files rm_list << Dir.glob("#{path}/*") rm_list.flatten! ["KPOINTS", "INCAR", "POTCAR", "POSCAR"].each do |file| rm_list.delete "#{path}/#{file}" end ##queeue rm_list += Dir.glob "#{@dir}/lock*" rm_list += Dir.glob "#{@dir}/*.sh" rm_list += Dir.glob "#{@dir}/*.log" rm_list += Dir.glob "#{@dir}/*.o*" ##remove rm_list.each do |file| FileUtils.rm_rf file end end |
#reset_next(io = $stdout) ⇒ Object
Generate a new vaspdir as ‘geomopt00’. Other directories, including old ‘geomopt00’, are removed.
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 139 def reset_next(io = $stdout) begin latest_dir.contcar prepare_next clean_queue_files rescue Errno::ENOENT latest_dir.reset_init(io) clean_queue_files rescue VaspUtils::Poscar::ParseError latest_dir.reset_init(io) clean_queue_files end end |
#reset_reincarnate ⇒ Object
Generate a new vaspdir as ‘geomopt00’. Other directories, including old ‘geomopt00’, are removed.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 155 def reset_reincarnate #CONTCAR を最後から解釈していく。 #全てだめだったら POSCAR を解釈する。 #全部だめだったら例外を投げる。 #CONTCAR を解釈できたディレクトリで INCAR, KPOINTS, POTCAR を取得。 #geomopt01 という名前でディレクトリを作る。 contcars = Dir.glob("#{@dir}/#{PREFIX}*/CONTCAR").sort.reverse contcars += Dir.glob("#{@dir}/#{PREFIX}*/POSCAR").sort.reverse poscar = nil path = nil contcars.each do |contcar| begin VaspUtils::Poscar.load_file contcar poscar = contcar path = File.dirname(contcar) break rescue VaspUtils::Poscar::ParseError next end end raise NoVaspDirError unless poscar new_dir = "#{@dir}/new_#{PREFIX}00" Dir.mkdir new_dir FileUtils.mv("#{path}/KPOINTS", "#{new_dir}/KPOINTS") FileUtils.mv("#{path}/INCAR" , "#{new_dir}/INCAR" ) FileUtils.mv("#{path}/POTCAR" , "#{new_dir}/POTCAR" ) FileUtils.mv(poscar , "#{new_dir}/POSCAR") rm_list = Dir.glob "#{@dir}/#{PREFIX}*" rm_list += Dir.glob "#{@dir}/lock*" rm_list += Dir.glob "#{@dir}/*.sh" rm_list += Dir.glob "#{@dir}/*.log" rm_list += Dir.glob "#{@dir}/*.o*" rm_list.each do |file| FileUtils.rm_rf file end FileUtils.mv new_dir, "#{@dir}/#{PREFIX}00" end |