Class: ChemScanner::Interpreter::Atom

Inherits:
Object
  • Object
show all
Defined in:
lib/chem_scanner/interpreter/element/atom.rb

Overview

Atom class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, rw_mol) ⇒ Atom

Returns a new instance of Atom.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 10

def initialize(node, rw_mol)
  @rw_mol = rw_mol

  @node = node

  @type = node.type
  @ext_type = node.ext_type
  @atnum = node.atnum
  @num_hydrogens = node.num_hydrogens
  @charge = node.charge
  @iso = node.iso
  @x = node.x || 0
  @y = node.y || 0
  @point = node.point

  @is_alias = node.is_alias
  @alias_text = node.alias_text.strip
  @warning = node.warning
  @warning_data = node.warning_data

  @is_polymer = node.is_polymer
end

Instance Attribute Details

#alias_textObject

Returns the value of attribute alias_text.



7
8
9
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 7

def alias_text
  @alias_text
end

#chargeObject

Returns the value of attribute charge.



7
8
9
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 7

def charge
  @charge
end

#ext_typeObject (readonly)

Returns the value of attribute ext_type.



8
9
10
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 8

def ext_type
  @ext_type
end

#is_aliasObject

Returns the value of attribute is_alias.



7
8
9
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 7

def is_alias
  @is_alias
end

#is_polymerObject (readonly)

Returns the value of attribute is_polymer.



8
9
10
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 8

def is_polymer
  @is_polymer
end

#pointObject (readonly)

Returns the value of attribute point.



8
9
10
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 8

def point
  @point
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 8

def type
  @type
end

#warningObject (readonly)

Returns the value of attribute warning.



8
9
10
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 8

def warning
  @warning
end

#warning_dataObject (readonly)

Returns the value of attribute warning_data.



8
9
10
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 8

def warning_data
  @warning_data
end

Instance Method Details

#cloneObject



80
81
82
83
84
85
86
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 80

def clone
  cnode = @node.clone
  clone = self.class.new(cnode, @rw_mol)
  clone.process

  clone
end

#get_idxObject



53
54
55
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 53

def get_idx
  get_rd_atom.get_idx
end

#get_rd_atomObject



49
50
51
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 49

def get_rd_atom
  @rw_mol.get_atom_with_bookmark(@node.id)
end

#idObject



57
58
59
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 57

def id
  @node.id
end

#inspectObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 61

def inspect
  (
    "#<Atom: id=#{@node.id}, " +
      "type: #{@type}, " +
      "external_type: #{@ext_type}, " +
      "atnum: #{@atnum}, " +
      "num_hydrogens: #{@num_hydrogens}, " +
      "charge: #{charge}, " +
      "iso: #{@iso}, " +
      "x: #{@x}, " +
      "y: #{@y}, " +
      "is_alias: #{is_alias}, " +
      "is_polymer: #{is_polymer}, " +
      "alias_text: #{alias_text}, " +
      "warning_data: #{@warning_data}, " +
      "warning: #{@warning} >"
  )
end

#processObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 33

def process
  # Set default to Carbon
  @atnum.negative? && @atnum = 6
  @rw_mol.add_atom(RDKitChem::Atom.new(@atnum), false)
  rd_atom = @rw_mol.get_last_atom
  @rw_mol.set_atom_bookmark(rd_atom, @node.id)

  @num_hydrogens >= 0 && rd_atom.set_num_explicit_hs(@num_hydrogens)
  rd_atom.set_formal_charge(@charge)
  rd_atom.set_isotope(@iso)
  conf = @rw_mol.get_conformer(0)
  conf.set_atom_pos(rd_atom.get_idx, RDKitChem::Point3D.new(@x, @y, 0))

  process_alias
end

#set_2d(coord_x, coord_y) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 88

def set_2d(coord_x, coord_y)
  @x = coord_x
  @y = coord_y

  conf = @rw_mol.get_conformer(0)
  conf.set_atom_pos(get_idx, RDKitChem::Point3D.new(@x, @y, 0))
end

#set_formal_charge(charge) ⇒ Object



96
97
98
99
100
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 96

def set_formal_charge(charge)
  @charge = charge
  rd_atom = get_rd_atom
  rd_atom.set_formal_charge(charge)
end

#set_polymerObject



102
103
104
105
# File 'lib/chem_scanner/interpreter/element/atom.rb', line 102

def set_polymer
  @is_alias = true
  @is_polymer = true
end