Class: AsciiChem::Model::Crystal

Inherits:
Node
  • Object
show all
Defined in:
lib/asciichem/model/crystal.rb

Overview

A crystal structure: unit cell parameters + space group + asymmetric-unit atoms with fractional coordinates.

Syntax:

crystal[NaCl](a=5.64,b=5.64,c=5.64,alpha=90,beta=90,gamma=90,sg=Fm-3m){
Na@f(0,0,0)
Cl@f(0.5,0.5,0.5)
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#==, #accept, #hash, short_name, #to_cml, #to_html, #to_latex, #to_mathml, #to_svg, #to_text

Constructor Details

#initialize(name: nil, a: nil, b: nil, c: nil, alpha: nil, beta: nil, gamma: nil, spacegroup: nil, atoms: []) ⇒ Crystal

Returns a new instance of Crystal.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/asciichem/model/crystal.rb', line 17

def initialize(name: nil, a: nil, b: nil, c: nil,
               alpha: nil, beta: nil, gamma: nil,
               spacegroup: nil, atoms: [])
  @name = name
  @a = a
  @b = b
  @c = c
  @alpha = alpha
  @beta = beta
  @gamma = gamma
  @spacegroup = spacegroup
  @atoms = atoms
end

Instance Attribute Details

#aObject

Returns the value of attribute a.



14
15
16
# File 'lib/asciichem/model/crystal.rb', line 14

def a
  @a
end

#alphaObject

Returns the value of attribute alpha.



14
15
16
# File 'lib/asciichem/model/crystal.rb', line 14

def alpha
  @alpha
end

#atomsObject

Returns the value of attribute atoms.



14
15
16
# File 'lib/asciichem/model/crystal.rb', line 14

def atoms
  @atoms
end

#bObject

Returns the value of attribute b.



14
15
16
# File 'lib/asciichem/model/crystal.rb', line 14

def b
  @b
end

#betaObject

Returns the value of attribute beta.



14
15
16
# File 'lib/asciichem/model/crystal.rb', line 14

def beta
  @beta
end

#cObject

Returns the value of attribute c.



14
15
16
# File 'lib/asciichem/model/crystal.rb', line 14

def c
  @c
end

#gammaObject

Returns the value of attribute gamma.



14
15
16
# File 'lib/asciichem/model/crystal.rb', line 14

def gamma
  @gamma
end

#nameObject

Returns the value of attribute name.



14
15
16
# File 'lib/asciichem/model/crystal.rb', line 14

def name
  @name
end

#spacegroupObject

Returns the value of attribute spacegroup.



14
15
16
# File 'lib/asciichem/model/crystal.rb', line 14

def spacegroup
  @spacegroup
end

Instance Method Details

#childrenObject



37
38
39
# File 'lib/asciichem/model/crystal.rb', line 37

def children
  atoms
end

#diagnostic_labelObject



41
42
43
# File 'lib/asciichem/model/crystal.rb', line 41

def diagnostic_label
  "Crystal(#{name || 'unnamed'})"
end

#to_sObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/asciichem/model/crystal.rb', line 45

def to_s
  params = []
  params << "a=#{a}" if a
  params << "b=#{b}" if b
  params << "c=#{c}" if c
  params << "alpha=#{alpha}" if alpha
  params << "beta=#{beta}" if beta
  params << "gamma=#{gamma}" if gamma
  params << "sg=#{spacegroup}" if spacegroup
  "crystal[#{name}](#{params.join(',')}){#{atoms.map(&:to_s).join(' ')}}"
end

#value_attributesObject



31
32
33
34
35
# File 'lib/asciichem/model/crystal.rb', line 31

def value_attributes
  { name: name, a: a, b: b, c: c, alpha: alpha,
    beta: beta, gamma: gamma, spacegroup: spacegroup,
    atoms: atoms }
end