Class: Chemicalml::Convention::Molecular::Constraints::BondMustReferenceAtomsInSameMolecule
- Inherits:
-
Constraint::DocumentConstraint
- Object
- Constraint
- Constraint::DocumentConstraint
- Chemicalml::Convention::Molecular::Constraints::BondMustReferenceAtomsInSameMolecule
- Defined in:
- lib/chemicalml/convention/molecular/constraints/bond_must_reference_atoms_in_same_molecule.rb
Overview
Bonds MUST reference atoms within the same parent molecule per the molecular convention.
Instance Method Summary collapse
Instance Method Details
#check(document) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/chemicalml/convention/molecular/constraints/bond_must_reference_atoms_in_same_molecule.rb', line 10 def check(document) violations = [] walk_nodes(document) do |node, path| next unless molecule?(node) known = atom_ids_within(node).to_set bonds_within(node).each do |bond| missing = atom_refs_of(bond).reject { |r| known.include?(r) } next if missing.empty? violations << violation( path: path.empty? ? "molecule[#{node.id}]" : path.join("/"), message: "bond #{bond.id.inspect} references atoms not in the same molecule: #{missing.inspect}" ) end end violations end |