Class: VaspUtils::VasprunXml
- Inherits:
-
Object
- Object
- VaspUtils::VasprunXml
show all
- Defined in:
- lib/vasputils/vasprunxml.rb
Defined Under Namespace
Classes: IllegalArgumentError
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of VasprunXml.
13
14
15
|
# File 'lib/vasputils/vasprunxml.rb', line 13
def initialize(data)
@data = data
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8
9
10
|
# File 'lib/vasputils/vasprunxml.rb', line 8
def data
@data
end
|
Class Method Details
.load_file(path) ⇒ Object
17
18
19
20
|
# File 'lib/vasputils/vasprunxml.rb', line 17
def self.load_file(path)
data = Nokogiri::XML(open(path))
self.new(data)
end
|
Instance Method Details
#bases ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/vasputils/vasprunxml.rb', line 31
def bases
results = @data.xpath("/modeling/calculation").map do |c|
c.xpath("./structure/crystal/varray[@name='basis']/v").map do |axis|
axis.text.strip.split.map {|i| i.to_f}
end
end
results
end
|
#calculation_basis ⇒ Object
115
116
117
118
119
120
121
|
# File 'lib/vasputils/vasprunxml.rb', line 115
def calculation_basis
results = []
@data.xpath('/modeling/calculation/structure/crystal/varray[@name="basis"]').each do |i|
results << i.xpath('v').children.map{|j| j.to_s.strip.split.map{|k| k.to_f}}
end
results
end
|
#calculation_cells ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/vasputils/vasprunxml.rb', line 132
def calculation_cells
basis = calculation_basis
elems = elements
poss_list = positions_list
results = []
poss_list.size.times do |i_step|
basis[i_step]
atoms = []
elems.size.times do |atom_id|
atoms << CrystalCell::Atom.new(elems[atom_id], poss_list[i_step][atom_id])
end
results << CrystalCell::Cell.new(basis[i_step], atoms)
end
results
end
|
#calculation_energies ⇒ Object
energies of each ionic step
111
112
113
|
# File 'lib/vasputils/vasprunxml.rb', line 111
def calculation_energies
@data.xpath("/modeling/calculation/energy/i[@name='e_fr_energy']").children.to_a.map{|i| i.to_s.to_f}
end
|
#elements ⇒ Object
124
125
126
127
128
|
# File 'lib/vasputils/vasprunxml.rb', line 124
def elements
@data.xpath("/modeling/atominfo/array[@name='atomtypes']/set/rc").map do |elem|
elem.xpath('./c').children[1].text
end
end
|
#fermi_energy ⇒ Object
97
98
99
|
# File 'lib/vasputils/vasprunxml.rb', line 97
def fermi_energy
@data.xpath("/modeling/calculation/dos/i[@name='efermi']").children.to_s.to_f
end
|
#num_atoms ⇒ Object
Also known as:
num_ions
101
102
103
|
# File 'lib/vasputils/vasprunxml.rb', line 101
def num_atoms
@data.xpath("/modeling/atominfo/atoms").children.to_s.to_i
end
|
#num_spins ⇒ Object
106
107
108
|
# File 'lib/vasputils/vasprunxml.rb', line 106
def num_spins
@data.xpath("/modeling/parameters/separator[@name='electronic']/separator[@name='electronic spin']/i[@name='ISPIN']").children.to_s.to_i
end
|
#nums_elements ⇒ Object
48
49
50
51
52
|
# File 'lib/vasputils/vasprunxml.rb', line 48
def nums_elements
@data.xpath("/modeling/atominfo/array[@name='atomtypes']/set/rc").map do |elem|
elem.xpath('./c').children[0].text.to_i
end
end
|
#partial_dos(ion, spin) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/vasputils/vasprunxml.rb', line 82
def partial_dos(ion, spin)
if (spin < 1) || (num_ions < ion)
raise IllegalArgumentError, "'ion' is indicated as #{ion}"
end
if (spin < 1) || (num_spins < spin)
raise IllegalArgumentError, "'spin' is indicated as #{spin}"
end
result = @data.xpath("/modeling/calculation/dos/partial/array/set/set[@comment='ion #{ion}']/set[@comment='spin #{spin}']/r").children.map do |elem|
elem.to_s.strip.split.map{|i| i.to_f}
end
result
end
|
#partial_dos_labels ⇒ Object
78
79
80
|
# File 'lib/vasputils/vasprunxml.rb', line 78
def partial_dos_labels
@data.xpath("/modeling/calculation/dos/partial/array/field").map{|i| i.children.to_s.strip}
end
|
#positions_list ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/vasputils/vasprunxml.rb', line 40
def positions_list
@data.xpath("/modeling/calculation").map do |c|
c.xpath("./structure/varray[@name='positions']/v").map do |pos|
pos.text.strip.split.map {|i| i.to_f}
end
end
end
|
#stress ⇒ Object
Return stress tensor of last ionic step
23
24
25
26
27
28
29
|
# File 'lib/vasputils/vasprunxml.rb', line 23
def stress
items = @data.xpath("/modeling/calculation/varray[@name='stress']/v").children
items = items.map do |line|
line.to_s.strip.split(/ +/).map {|item| item.to_f}
end
items[-3..-1]
end
|
#total_dos(spin) ⇒ Object
Return an array of [energy, total, integrated] for spin. ‘spin’ is indicated by number started from 1 (should be 1 or 2). If the ‘spin’ does not exist, raise IllegalArgumentError
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/vasputils/vasprunxml.rb', line 63
def total_dos(spin)
if (spin < 1) || (num_spins < spin)
raise IllegalArgumentError, "'spin' is indicated as #{spin}"
end
result = @data.xpath("/modeling/calculation/dos/total/array/set/set[@comment='spin #{spin}']/r").children.map do |elem|
elem.to_s.strip.split.map{|i| i.to_f}
end
result
end
|
#total_dos_labels ⇒ Object
74
75
76
|
# File 'lib/vasputils/vasprunxml.rb', line 74
def total_dos_labels
@data.xpath("/modeling/calculation/dos/total/array/field").map{|i| i.children.to_s}
end
|