def test_species_isomorphism(): h2.graph = None h2_copy = Species(name='H2', atoms=[h_a, h_b], charge=0, mult=1) h2_copy.graph = None with pytest.raises(NoMolecularGraph): assert mol_graphs.species_are_isomorphic(h2, h2_copy) # With molecular graphs the species should be isomorphic mol_graphs.make_graph(h2) mol_graphs.make_graph(h2_copy) assert mol_graphs.species_are_isomorphic(h2, h2_copy) # Shift one of the atoms far away and remake the graph h2_copy.atoms[1].translate(vec=np.array([10, 0, 0])) mol_graphs.make_graph(h2_copy) assert mol_graphs.species_are_isomorphic(h2, h2_copy) is False # Generating a pair of conformers that are isomporhpic should return that # the species are again isomorphic h2.conformers = [ Conformer(name='h2_conf', atoms=[h_a, h_b], charge=0, mult=1) ] h2_copy.conformers = [ Conformer(name='h2_conf', atoms=[h_a, h_b], charge=0, mult=1) ] assert mol_graphs.species_are_isomorphic(h2, h2_copy)
def test_species_conformers_isomorphic(): h2_a = Molecule(name='H2', atoms=[Atom('H'), Atom('H', x=0.7)]) h2_b = Molecule(name='H2', atoms=[Atom('H'), Atom('H', x=1.5)]) assert not mol_graphs.species_are_isomorphic(h2_a, h2_b) # Should raise an exception for two non-isomorphic graphs with pytest.raises(NoMapping): mol_graphs.get_mapping(h2_a.graph, h2_b.graph) h2_a.conformers = None h2_b.conformers = [ Conformer(name='H2', atoms=[Atom('H'), Atom('H', x=0.7)]) ] assert mol_graphs.species_are_isomorphic(h2_a, h2_b)
def f_b_isomorphic_to_r_p(forwards, backwards, reactant, product): """Is the forward/backward displacement to reactants/products?""" if any(mol.atoms is None for mol in (forwards, backwards)): logger.warning( 'Atoms not set in the output. Cannot calculate isomorphisms') return False if species_are_isomorphic(backwards, reactant) and species_are_isomorphic( forwards, product): logger.info( 'Forwards displacement lead to products and backwards reactants') return True if species_are_isomorphic(forwards, reactant) and species_are_isomorphic( backwards, product): logger.info( 'Backwards displacement lead to products and forwards to reactants' ) return True return False
def find_tss(reaction): """Find all the possible the transition states of a reaction Arguments: reaction (list(autode.reaction.Reaction)): Reaction Returns: list: list of transition state objects """ logger.info('Finding possible transition states') reactant, product = reaction.reactant, reaction.product if species_are_isomorphic(reactant, product): logger.error('Reactant and product complexes are isomorphic. Cannot' ' find a TS') return None bond_rearrs = get_bond_rearrangs(reactant, product, name=str(reaction)) if bond_rearrs is None: logger.error('Could not find a set of forming/breaking bonds') return None tss = [] for bond_rearrangement in bond_rearrs: logger.info(f'Locating transition state using active bonds ' f'{bond_rearrangement.all}') ts = get_ts(reaction, reactant, bond_rearrangement) if ts is not None: tss.append(ts) if len(tss) == 0: logger.error('Did not find any transition state(s)') return None logger.info( f'Found *{len(tss)}* transition state(s) that lead to products') return tss