Class: Chemicalml::Convention::Molecular::Constraints::AtomCoordinatesMustBePaired

Inherits:
Constraint::NodeConstraint show all
Defined in:
lib/chemicalml/convention/molecular/constraints/atom_coordinates_must_be_paired.rb

Instance Method Summary collapse

Methods inherited from Constraint::NodeConstraint

#check

Instance Method Details

#check_node(node, path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/chemicalml/convention/molecular/constraints/atom_coordinates_must_be_paired.rb', line 8

def check_node(node, path)
  return [] unless node.is_a?(Chemicalml::Cml::Role::Atom)

  violations = []
  has_x2 = !node.x2.to_s.empty?
  has_y2 = !node.y2.to_s.empty?
  if has_x2 != has_y2
    violations << violation(path: path.empty? ? "atom" : path.join("/"),
                            message: "x2 and y2 must both be present or both absent")
  end

  has_x3 = !node.x3.to_s.empty?
  has_y3 = !node.y3.to_s.empty?
  has_z3 = !node.z3.to_s.empty?
  if [has_x3, has_y3, has_z3].any? && ![has_x3, has_y3, has_z3].all?
    violations << violation(path: path.empty? ? "atom" : path.join("/"),
                            message: "x3, y3, and z3 must all be present together")
  end
  violations
end