vasputils 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. data/Gemfile +1 -1
  2. data/VERSION +1 -1
  3. data/bin/lsvasp +90 -0
  4. data/bin/qsubvasp +42 -6
  5. data/bin/runvasp +35 -0
  6. data/lib/vasputils/calcinspector.rb +15 -15
  7. data/lib/vasputils/incar.rb +30 -30
  8. data/lib/vasputils/kpoints.rb +34 -34
  9. data/lib/vasputils/outcar.rb +45 -45
  10. data/lib/vasputils/poscar.rb +145 -145
  11. data/lib/vasputils/potcar.rb +12 -12
  12. data/lib/vasputils/vaspdir.rb +52 -77
  13. data/lib/vasputils/vaspgeomopt.rb +114 -0
  14. data/memo.txt +7 -0
  15. data/test/test_vaspdir.rb +24 -6
  16. data/test/test_vaspgeomopt.rb +95 -0
  17. data/test/{vaspdir/finished/lock → vaspgeomopt/ended-Iter1/try00/CONTCAR} +0 -0
  18. data/test/{vaspdir/locked/lock → vaspgeomopt/ended-Iter1/try00/INCAR} +0 -0
  19. data/test/{vaspdir/started/lock → vaspgeomopt/ended-Iter1/try00/KPOINTS} +0 -0
  20. data/test/vaspgeomopt/ended-Iter1/try00/OUTCAR +0 -0
  21. data/test/vaspgeomopt/ended-Iter1/try00/POSCAR +0 -0
  22. data/test/vaspgeomopt/ended-Iter1/try00/POTCAR +0 -0
  23. data/test/vaspgeomopt/ended-Iter1/try01/INCAR +0 -0
  24. data/test/vaspgeomopt/ended-Iter1/try01/KPOINTS +0 -0
  25. data/test/vaspgeomopt/ended-Iter1/try01/OUTCAR +16 -0
  26. data/test/vaspgeomopt/ended-Iter1/try01/POSCAR +0 -0
  27. data/test/vaspgeomopt/ended-Iter1/try01/POTCAR +0 -0
  28. data/test/vaspgeomopt/ended-Iter2/try00/CONTCAR +0 -0
  29. data/test/vaspgeomopt/ended-Iter2/try00/INCAR +0 -0
  30. data/test/vaspgeomopt/ended-Iter2/try00/KPOINTS +0 -0
  31. data/test/vaspgeomopt/ended-Iter2/try00/OUTCAR +0 -0
  32. data/test/vaspgeomopt/ended-Iter2/try00/POSCAR +0 -0
  33. data/test/vaspgeomopt/ended-Iter2/try00/POTCAR +0 -0
  34. data/test/vaspgeomopt/ended-Iter2/try01/INCAR +0 -0
  35. data/test/vaspgeomopt/ended-Iter2/try01/KPOINTS +0 -0
  36. data/test/vaspgeomopt/ended-Iter2/try01/OUTCAR +18 -0
  37. data/test/vaspgeomopt/ended-Iter2/try01/POSCAR +0 -0
  38. data/test/vaspgeomopt/ended-Iter2/try01/POTCAR +0 -0
  39. data/test/vaspgeomopt/not-yet/try00/INCAR +0 -0
  40. data/test/vaspgeomopt/not-yet/try00/KPOINTS +0 -0
  41. data/test/vaspgeomopt/not-yet/try00/POSCAR +0 -0
  42. data/test/vaspgeomopt/not-yet/try00/POTCAR +0 -0
  43. data/test/vaspgeomopt/prepare_next/try00/CHG +0 -0
  44. data/test/vaspgeomopt/prepare_next/try00/CHGCAR +0 -0
  45. data/test/vaspgeomopt/prepare_next/try00/CONTCAR +0 -0
  46. data/test/vaspgeomopt/prepare_next/try00/DOSCAR +0 -0
  47. data/test/vaspgeomopt/prepare_next/try00/EIGENVAL +0 -0
  48. data/test/vaspgeomopt/prepare_next/try00/INCAR +0 -0
  49. data/test/vaspgeomopt/prepare_next/try00/KPOINTS +0 -0
  50. data/test/vaspgeomopt/prepare_next/try00/OSZICAR +0 -0
  51. data/test/vaspgeomopt/prepare_next/try00/OUTCAR +0 -0
  52. data/test/vaspgeomopt/prepare_next/try00/PCDAT +0 -0
  53. data/test/vaspgeomopt/prepare_next/try00/POSCAR +0 -0
  54. data/test/vaspgeomopt/prepare_next/try00/POTCAR +0 -0
  55. data/test/vaspgeomopt/prepare_next/try00/WAVECAR +0 -0
  56. data/test/vaspgeomopt/prepare_next/try00/XDATCAR +0 -0
  57. data/test/vaspgeomopt/prepare_next/try00/vasprun.xml +0 -0
  58. data/test/vaspgeomopt/started/try00/INCAR +0 -0
  59. data/test/vaspgeomopt/started/try00/KPOINTS +0 -0
  60. data/test/vaspgeomopt/started/try00/POSCAR +0 -0
  61. data/test/vaspgeomopt/started/try00/POTCAR +0 -0
  62. data/test/vaspgeomopt/till01/try00/CONTCAR +0 -0
  63. data/test/vaspgeomopt/till01/try00/INCAR +0 -0
  64. data/test/vaspgeomopt/till01/try00/KPOINTS +0 -0
  65. data/test/vaspgeomopt/till01/try00/OUTCAR +0 -0
  66. data/test/vaspgeomopt/till01/try00/POSCAR +0 -0
  67. data/test/vaspgeomopt/till01/try00/POTCAR +0 -0
  68. data/test/vaspgeomopt/till01/try01/INCAR +0 -0
  69. data/test/vaspgeomopt/till01/try01/KPOINTS +0 -0
  70. data/test/vaspgeomopt/till01/try01/POSCAR +0 -0
  71. data/test/vaspgeomopt/till01/try01/POTCAR +0 -0
  72. data/vasputils.gemspec +66 -14
  73. metadata +86 -33
  74. data/bin/repeatvasp +0 -47
  75. data/lib/vasputils/calcrepeater.rb +0 -27
  76. data/lib/vasputils/calcseries.rb +0 -98
  77. data/test/test_calcrepeater.rb +0 -69
  78. data/test/test_calcseries.rb +0 -77
@@ -0,0 +1,114 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require "pp"
5
+ require "fileutils"
6
+
7
+ require "rubygems"
8
+ gem "comana"
9
+ require "comana"
10
+
11
+ require "vasputils/vaspdir"
12
+
13
+ #
14
+ #
15
+ #
16
+ class VaspGeomOpt < Comana
17
+ class NoVaspDirError < Exception; end
18
+ class LatestDirStartedError < Exception; end
19
+ class NoIntegerEndedNameError < Exception; end
20
+
21
+ def initialize(dir)
22
+ super(dir)
23
+ latest_dir # to check.
24
+ end
25
+
26
+ # Return incremented name.
27
+ # If the name of VaspDir ends with string of integer,
28
+ # return incremental value with the basename.
29
+ # If not ended with integer, this method assume "00"
30
+ def self.next_name(name)
31
+ basename = name.sub(/(\d*)$/, "")
32
+ new_num = $1.to_i + 1
33
+ return basename + sprintf("%02d", new_num)
34
+ end
35
+
36
+ # 注目した VaspDir が yet なら実行し、続ける。
37
+ # yet 以外なら例外。
38
+ # VaspDir になっているか。
39
+ def calculate
40
+ #pp latest_dir.dir
41
+ $stdout.puts "Calculate #{latest_dir.dir}"
42
+ $stdout.flush
43
+
44
+ #pp latest_dir
45
+
46
+ latest_dir.start
47
+ #dir = latest_dir
48
+ #while (! finished?)
49
+ # raise LatestDirStartedError if dir.state == :started
50
+ # dir.start
51
+ # if dir.finished?
52
+ # break
53
+ # else
54
+ # #dir = prepare_next
55
+ # puts "Geometry optimization fihished. Exit."
56
+ # end
57
+ #end
58
+ #puts "Geometry optimization fihished. Exit."
59
+ sleep 1 # for interrupt
60
+ end
61
+
62
+ # latest_dir から返って来る最新の VaspDir が finished? で真を返し、
63
+ # かつ Iteration が 1 であるか。
64
+ # Note: even when the geometry optimization does not include lattice shape,
65
+ # calculate will continued till to converge to Iter 1 calculation.
66
+ def finished?
67
+ return false unless latest_dir.finished?
68
+ return false unless latest_dir.outcar[:ionic_steps] == 1
69
+ return true
70
+ end
71
+
72
+ private
73
+
74
+ # Generate next directory of latest_dir.
75
+ def prepare_next
76
+ new_dir = self.class.next_name(latest_dir.dir)
77
+ Dir.mkdir new_dir
78
+ FileUtils.cp("#{latest_dir.dir}/CHG" , "#{new_dir}/CHG" )
79
+ FileUtils.cp("#{latest_dir.dir}/CHGCAR" , "#{new_dir}/CHGCAR" )
80
+ FileUtils.cp("#{latest_dir.dir}/DOSCAR" , "#{new_dir}/DOSCAR" )
81
+ FileUtils.cp("#{latest_dir.dir}/EIGENVAL", "#{new_dir}/EIGENVAL")
82
+ FileUtils.cp("#{latest_dir.dir}/INCAR" , "#{new_dir}/INCAR" )
83
+ FileUtils.cp("#{latest_dir.dir}/KPOINTS" , "#{new_dir}/KPOINTS" )
84
+ FileUtils.cp("#{latest_dir.dir}/OSZICAR" , "#{new_dir}/OSZICAR" )
85
+ FileUtils.cp("#{latest_dir.dir}/PCDAT" , "#{new_dir}/PCDAT" )
86
+ FileUtils.cp("#{latest_dir.dir}/POTCAR" , "#{new_dir}/POTCAR" )
87
+ FileUtils.cp("#{latest_dir.dir}/WAVECAR" , "#{new_dir}/WAVECAR" )
88
+ FileUtils.cp("#{latest_dir.dir}/XDATCAR" , "#{new_dir}/XDATCAR" )
89
+ FileUtils.cp("#{latest_dir.dir}/CONTCAR" , "#{new_dir}/POSCAR" ) # change name
90
+ # without POSCAR, OUTCAR, vasprun.xml
91
+ VaspDir.new(new_dir)
92
+ end
93
+
94
+ # Find latest VaspDir.
95
+ # Return a last VaspDir which has the name by name sort
96
+ # and which can be made as a VaspDir instance.
97
+ # Note: in a series of geometry optimization,
98
+ # the directory names should have a rule of naming
99
+ # which can define a method <=>.
100
+ # Usually, it is simple sort of String.
101
+ def latest_dir
102
+ Dir.glob("#{@dir}/*").sort.reverse.find do |dir|
103
+ begin
104
+ vd = VaspDir.new(dir)
105
+ return vd
106
+ rescue VaspDir::InitializeError
107
+ next
108
+ end
109
+ end
110
+ raise NoVaspDirError
111
+ end
112
+
113
+ end
114
+
data/memo.txt ADDED
@@ -0,0 +1,7 @@
1
+ 0.0.4 release
2
+ Using Comana library.
3
+ Add runvasp.
4
+ Modify VaspDir.
5
+ Add VaspGeomOpt.
6
+
7
+ 0.0.3 release
data/test/test_vaspdir.rb CHANGED
@@ -16,7 +16,28 @@ require "vasputils/vaspdir.rb"
16
16
 
17
17
  class VaspDir < Comana
18
18
  attr_reader :mode
19
- public :finished?
19
+
20
+ def calculate
21
+ generated_files = [
22
+ "CHG",
23
+ "CHGCAR",
24
+ "CONTCAR",
25
+ "DOSCAR",
26
+ "EIGENVAL",
27
+ "IBZKPT",
28
+ "OSZICAR",
29
+ "OUTCAR",
30
+ "PCDAT",
31
+ "WAVECAR",
32
+ "XDATCAR",
33
+ "machines",
34
+ "vasprun.xml",
35
+ ]
36
+ generated_files.map!{|i| "#{@dir}/#{i}"}
37
+ command = "touch #{generated_files.join(" ")}"
38
+
39
+ system command
40
+ end
20
41
  end
21
42
 
22
43
 
@@ -67,7 +88,7 @@ class TC_VaspDir < Test::Unit::TestCase
67
88
  end
68
89
 
69
90
  def test_calculate
70
- lock_dir = "test/vaspdir/not-yet/lock"
91
+ lock_dir = "test/vaspdir/not-yet/comana_lock"
71
92
  Dir.rmdir(lock_dir) if Dir.exist?(lock_dir)
72
93
  #pp @vd00;exit
73
94
  #@vd00.calculate
@@ -81,7 +102,7 @@ class TC_VaspDir < Test::Unit::TestCase
81
102
  assert(FileTest.exist? "test/vaspdir/not-yet/POSCAR")
82
103
  assert(FileTest.exist? "test/vaspdir/not-yet/POTCAR")
83
104
 
84
- lock_dir = "test/vaspdir/not-yet/lock"
105
+ lock_dir = "test/vaspdir/not-yet/comana_lock"
85
106
  Dir.rmdir(lock_dir) if Dir.exist?(lock_dir)
86
107
  end
87
108
 
@@ -114,9 +135,6 @@ class TC_VaspDir < Test::Unit::TestCase
114
135
  GENERATED_FILES_VD00.each do |file|
115
136
  FileUtils.rm file if File.exist? file
116
137
  end
117
-
118
- #lock_dir = "test/vaspdir/not-yet/lock"
119
- #Dir.rmdir(lock_dir) if Dir.exist?(lock_dir)
120
138
  end
121
139
 
122
140
  end
@@ -0,0 +1,95 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require "fileutils"
5
+ require "test/unit"
6
+ require "vasputils/vaspgeomopt.rb"
7
+
8
+
9
+ class VaspGeomOpt < Comana
10
+ public :latest_dir, :prepare_next
11
+ end
12
+
13
+ class TC_VaspGeomOpt < Test::Unit::TestCase
14
+ TEST_DIR = "test/vaspgeomopt"
15
+ def setup
16
+ @vgo00 = VaspGeomOpt.new( TEST_DIR + "/not-yet")
17
+ @vgo01 = VaspGeomOpt.new( TEST_DIR + "/started")
18
+ @vgo02 = VaspGeomOpt.new( TEST_DIR + "/till01")
19
+ @vgo03 = VaspGeomOpt.new( TEST_DIR + "/ended-Iter1")
20
+ @vgo04 = VaspGeomOpt.new( TEST_DIR + "/ended-Iter2")
21
+ end
22
+
23
+ def test_initialize
24
+ assert_raise(VaspGeomOpt::NoVaspDirError){
25
+ VaspGeomOpt.new( TEST_DIR + "/not-geomopt")
26
+ }
27
+ end
28
+
29
+ def test_latest_dir
30
+ assert_equal("#{@vgo00.dir}/try00", @vgo00.latest_dir.dir)
31
+ assert_equal("#{@vgo01.dir}/try00", @vgo01.latest_dir.dir)
32
+ assert_equal("#{@vgo02.dir}/try01", @vgo02.latest_dir.dir)
33
+ assert_equal("#{@vgo03.dir}/try01", @vgo03.latest_dir.dir)
34
+ end
35
+
36
+ def test_finished?
37
+ assert_equal(false, @vgo00.finished?)
38
+ assert_equal(false, @vgo01.finished?)
39
+ assert_equal(false, @vgo02.finished?)
40
+ assert_equal(true , @vgo03.finished?)
41
+ assert_equal(false, @vgo04.finished?)
42
+ end
43
+
44
+ def test_next_name
45
+ assert_equal( "try01" , VaspGeomOpt.next_name("try00"))
46
+ assert_equal( "try01" , VaspGeomOpt.next_name("try0"))
47
+ assert_equal( "try10" , VaspGeomOpt.next_name("try09"))
48
+ assert_equal( "try11" , VaspGeomOpt.next_name("try10"))
49
+ assert_equal( "try100", VaspGeomOpt.next_name("try99"))
50
+ assert_equal( "01" , VaspGeomOpt.next_name("00"))
51
+ assert_equal( "try01" , VaspGeomOpt.next_name("try"))
52
+ #assert_raise(VaspGeomOpt::NoIntegerEndedNameError){VaspGeomOpt.next_name("try")}
53
+ end
54
+
55
+ def test_prepare_next
56
+ dir = TEST_DIR + "/prepare_next"
57
+ old_number_dir = dir + "/try00"
58
+ new_number_dir = dir + "/try01"
59
+
60
+ if Dir.exist?(new_number_dir)
61
+ Dir.glob(new_number_dir + "/*").each do |file|
62
+ FileUtils.rm file
63
+ end
64
+ Dir.rmdir new_number_dir
65
+ end
66
+
67
+ vgo = VaspGeomOpt.new(dir)
68
+ vgo.prepare_next
69
+ assert(Dir.exist?(new_number_dir))
70
+ assert(File.exist?(new_number_dir + "/CHG" ))
71
+ assert(File.exist?(new_number_dir + "/CHGCAR" ))
72
+ assert(File.exist?(new_number_dir + "/DOSCAR" ))
73
+ assert(File.exist?(new_number_dir + "/EIGENVAL"))
74
+ assert(File.exist?(new_number_dir + "/INCAR" ))
75
+ assert(File.exist?(new_number_dir + "/KPOINTS" ))
76
+ assert(File.exist?(new_number_dir + "/OSZICAR" ))
77
+ assert(File.exist?(new_number_dir + "/PCDAT" ))
78
+ assert(File.exist?(new_number_dir + "/POTCAR" ))
79
+ assert(File.exist?(new_number_dir + "/WAVECAR" ))
80
+ assert(File.exist?(new_number_dir + "/XDATCAR" ))
81
+ assert(File.exist?(new_number_dir + "/POSCAR" ))
82
+ assert(! File.exist?(new_number_dir + "/CONTCAR" ))
83
+ assert(! File.exist?(new_number_dir + "/OUTCAR" ))
84
+ assert(! File.exist?(new_number_dir + "/vasprun.xml" ))
85
+
86
+ if Dir.exist?(new_number_dir)
87
+ Dir.glob(new_number_dir + "/*").each do |file|
88
+ FileUtils.rm file
89
+ end
90
+ Dir.rmdir new_number_dir
91
+ end
92
+ end
93
+
94
+ end
95
+
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,16 @@
1
+ ----------------------------------------- Iteration 1( 1) ---------------------------------------
2
+ ----------------------------------------- Iteration 1( 2) ---------------------------------------
3
+ General timing and accounting informations for this job:
4
+ ========================================================
5
+
6
+ Total CPU time used (sec): 61.952
7
+ User time (sec): 61.788
8
+ System time (sec): 0.164
9
+ Elapsed time (sec): 62.091
10
+
11
+ Maximum memory used (kb): 103600.
12
+ Average memory used (kb): 0.
13
+
14
+ Minor page faults: 108508
15
+ Major page faults: 0
16
+ Voluntary context switches: 1
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,18 @@
1
+ ----------------------------------------- Iteration 1( 1) ---------------------------------------
2
+ ----------------------------------------- Iteration 1( 2) ---------------------------------------
3
+ ----------------------------------------- Iteration 2( 1) ---------------------------------------
4
+ ----------------------------------------- Iteration 2( 2) ---------------------------------------
5
+ General timing and accounting informations for this job:
6
+ ========================================================
7
+
8
+ Total CPU time used (sec): 61.952
9
+ User time (sec): 61.788
10
+ System time (sec): 0.164
11
+ Elapsed time (sec): 62.091
12
+
13
+ Maximum memory used (kb): 103600.
14
+ Average memory used (kb): 0.
15
+
16
+ Minor page faults: 108508
17
+ Major page faults: 0
18
+ Voluntary context switches: 1
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes