def _get_new_ref(self, existing_refs):
<EOL>ref0 = existing_refs[<NUM_LIT:0>]<EOL>for ref in existing_refs:<EOL><INDENT>result = None<EOL>for n in sorted(self.graph.neighbors[ref]):<EOL><INDENT>if self.new_index[n] > self.new_index[ref0]:<EOL><INDENT>continue<EOL><DEDENT>if n in existing_refs:<EOL><INDENT>continue<EOL><DEDENT>if result is None or self.graph.numbers[n] <= self.graph.numbers[result]:<EOL><INDENT>result = n<EOL><DEDENT><DEDENT>if result is not None:<EOL><INDENT>return result<EOL><DEDENT><DEDENT>raise RuntimeError("<STR_LIT>")<EOL>
Get a new reference atom for a row in the ZMatrix

           The reference atoms should obey the following conditions:
             - They must be different
             - They must be neighbours in the bond graph
             - They must have an index lower than the current atom

           If multiple candidate refs can be found, take the heaviest atom