Class: Crystal
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
TODO define select/reject etc for crystal module.
-
#alpha ⇒ Object
readonly
TODO define select/reject etc for crystal module.
-
#atoms ⇒ Object
readonly
TODO define select/reject etc for crystal module.
-
#b ⇒ Object
readonly
TODO define select/reject etc for crystal module.
-
#beta ⇒ Object
readonly
TODO define select/reject etc for crystal module.
-
#c ⇒ Object
readonly
TODO define select/reject etc for crystal module.
-
#gamma ⇒ Object
readonly
TODO define select/reject etc for crystal module.
Instance Method Summary collapse
- #<<(arg) ⇒ Object
- #[](i, j = nil) ⇒ Object
- #[]=(i, v) ⇒ Object
- #frac(v) ⇒ Object
-
#initialize(*args) ⇒ Crystal
constructor
A new instance of Crystal.
- #real(v) ⇒ Object
- #surface(v, p, tol = 0) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ Crystal
Returns a new instance of Crystal.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/kristal.rb', line 11 def initialize *args @a = @b = @c = args[0].to_f @alpha = @beta = @gamma = 90.0 if args.length > 2 @b = args[1] @c = args[2] end case args.length when 4 @beta = args[3] when 6 @alpha = args[3] @beta = args[4] @gamma = args[5] end @abc2xyz = conversion_matrix @xyz2abc = @abc2xyz.inv @atoms = Collection.new @crystal = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object (private)
60 61 62 |
# File 'lib/kristal.rb', line 60 def method_missing *args, &block @atoms.send(*args, &block) end |
Instance Attribute Details
#a ⇒ Object (readonly)
TODO define select/reject etc for crystal module.
10 11 12 |
# File 'lib/kristal.rb', line 10 def a @a end |
#alpha ⇒ Object (readonly)
TODO define select/reject etc for crystal module.
10 11 12 |
# File 'lib/kristal.rb', line 10 def alpha @alpha end |
#atoms ⇒ Object (readonly)
TODO define select/reject etc for crystal module.
10 11 12 |
# File 'lib/kristal.rb', line 10 def atoms @atoms end |
#b ⇒ Object (readonly)
TODO define select/reject etc for crystal module.
10 11 12 |
# File 'lib/kristal.rb', line 10 def b @b end |
#beta ⇒ Object (readonly)
TODO define select/reject etc for crystal module.
10 11 12 |
# File 'lib/kristal.rb', line 10 def beta @beta end |
#c ⇒ Object (readonly)
TODO define select/reject etc for crystal module.
10 11 12 |
# File 'lib/kristal.rb', line 10 def c @c end |
#gamma ⇒ Object (readonly)
TODO define select/reject etc for crystal module.
10 11 12 |
# File 'lib/kristal.rb', line 10 def gamma @gamma end |
Instance Method Details
#<<(arg) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kristal.rb', line 31 def << arg case arg when Atom arg.crystal = self @atoms << arg @crystal << CAtom.new(arg) when CAtom arg.crystal = self @atoms << arg.atom @crystal << arg when Collection arg.crystal = self @atoms = arg @crystal = [].tap{|t| @atoms.each{|a| t << CAtom.new(a)}} end return self end |
#[](i, j = nil) ⇒ Object
50 51 52 |
# File 'lib/kristal.rb', line 50 def [] i, j = nil j.nil?? @crystal[i] : @crystal[i,j] end |
#[]=(i, v) ⇒ Object
53 54 55 |
# File 'lib/kristal.rb', line 53 def []= i, v @crystal[i] = CAtom.new(arg) if v.is_a? Atom end |
#frac(v) ⇒ Object
48 |
# File 'lib/kristal.rb', line 48 def frac(v) @xyz2abc * v.to_v end |
#real(v) ⇒ Object
49 |
# File 'lib/kristal.rb', line 49 def real(v) @abc2xyz * v.to_v end |