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 =
class InitializeError < Comana::ComputationManager::InitializeError; end
"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_initialize ⇒ 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
Returns a new instance of VaspGeometryOptimizer.
20 21 22 23 24 25 26 27 28 |
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 20 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”
34 35 36 37 |
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 34 def self.next_name(name) name =~ /^(.*#{PREFIX})(\d+)/ return sprintf("%s%02d", $1, $2.to_i + 1) end |
Instance Method Details
#calculate ⇒ Object
注目した VaspDir が yet なら実行し、続ける。yet 以外なら例外。VaspDir になっているか。
43 44 45 46 47 48 |
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 43 def calculate $stdout.puts "Calculate #{latest_dir.dir}" $stdout.flush latest_dir.start 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.
54 55 56 57 58 |
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 54 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.
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 67 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_initialize ⇒ Object
Keep ‘geomopt00/POSCAR,POTCAR,INCAR,POTCAR’, remove others.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 80 def reset_initialize poscars = Dir.glob("#{@dir}/#{PREFIX}*/POSCAR").sort #poscar = nil path = nil # Find the first geometory optimization 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 files = Dir.glob("#{@dir}/*") files.delete( path) rm_list += files 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.
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/vasputils/vaspgeometryoptimizer.rb', line 116 def reset_next(io = $stdout) begin latest_dir.contcar prepare_next clean_queue_files rescue Errno::ENOENT latest_dir.reset_initialize(io) clean_queue_files rescue VaspUtils::Poscar::ParseError latest_dir.reset_initialize(io) clean_queue_files end end |
#reset_reincarnate ⇒ Object
Generate a new vaspdir as ‘geomopt00’. Other directories, including old ‘geomopt00’, are removed.
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/vaspgeometryoptimizer.rb', line 132 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 |