Class: Crystal

Inherits:
Object show all
Defined in:
lib/kristal.rb,
lib/lib/crystal/surface.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#aObject (readonly)

TODO define select/reject etc for crystal module.



10
11
12
# File 'lib/kristal.rb', line 10

def a
  @a
end

#alphaObject (readonly)

TODO define select/reject etc for crystal module.



10
11
12
# File 'lib/kristal.rb', line 10

def alpha
  @alpha
end

#atomsObject (readonly)

TODO define select/reject etc for crystal module.



10
11
12
# File 'lib/kristal.rb', line 10

def atoms
  @atoms
end

#bObject (readonly)

TODO define select/reject etc for crystal module.



10
11
12
# File 'lib/kristal.rb', line 10

def b
  @b
end

#betaObject (readonly)

TODO define select/reject etc for crystal module.



10
11
12
# File 'lib/kristal.rb', line 10

def beta
  @beta
end

#cObject (readonly)

TODO define select/reject etc for crystal module.



10
11
12
# File 'lib/kristal.rb', line 10

def c
  @c
end

#gammaObject (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

#surface(v, p, tol = 0) ⇒ Object



2
3
4
# File 'lib/lib/crystal/surface.rb', line 2

def surface v, p, tol = 0
  Surface.new(surface_converter(v), real(p), tol)
end

#to_sObject



56
57
58
# File 'lib/kristal.rb', line 56

def to_s
  String.new.tap{|s| @crystal.each{|e| s << e.to_s << "\n"}}
end