def test_fwd_reaction(): mol1 = Molecule(smiles="CC(=O)O", sanitize=True) mol2 = Molecule(smiles="NC", sanitize=True) reaction = Reaction( mols=[mol1, mol2], smarts="[C:1](=[O:2])-[OD1].[N!H0:3]>>[C:1](=[O:2])[N:3]") products = reaction.apply() assert len(products) == 1 assert len(products[0]) == 1 assert products[0][0].smiles == "CNC(C)=O"
def setup_complete_tree(fresh_tree, mocker, mock_stock): tree = fresh_tree state1 = mocker.MagicMock() state1.mols = [ TreeMolecule( parent=None, transform=0, smiles="CN1CCC(C(=O)c2cccc(NC(=O)c3ccc(F)cc3)c2F)CC1", ) ] state1.in_stock_list = [False] state1.score = 0.049 state1.is_solved = False node1 = mocker.MagicMock() node1.state = state1 node1.parent = None node1.is_expanded = True action1 = ( "([C:2]-[CH;D3;+0:1](-[C:3])-[C;H0;D3;+0:4](=[O;H0;D1;+0:6])-[c:5])" ">>(Cl-[CH;D3;+0:1](-[C:2])-[C:3]).(N#[C;H0;D2;+0:4]-[c:5]).([OH2;D0;+0:6])" ) reaction1 = Reaction(state1.mols[0], action1) reaction1.apply() node1.__getitem__.return_value = {"action": reaction1} node1.is_terminal.return_value = False tree.root = node1 state2 = mocker.MagicMock() state2.mols = [ TreeMolecule(parent=state1.mols[0], smiles=smiles) for smiles in ["CN1CCC(Cl)CC1", "N#Cc1cccc(NC(=O)c2ccc(F)cc2)c1F", "O"] ] state2.in_stock_list = [True, False, True] state2.score = 0.68 state2.is_solved = False node2 = mocker.MagicMock() node2.parent = node1 node2.is_expanded = True node2.state = state2 node1.promising_child.return_value = node2 node1.children.return_value = [node2] action2 = ( "([O;D1;H0:2]=[C;H0;D3;+0:1](-[c:3])-[NH;D2;+0:4]-[c:5])" ">>(Cl-[C;H0;D3;+0:1](=[O;D1;H0:2])-[c:3]).([NH2;D1;+0:4]-[c:5])") reaction2 = Reaction(state2.mols[1], action2) reaction2.apply() node2.__getitem__.return_value = {"action": reaction2} state3 = mocker.MagicMock() state3.mols = [ TreeMolecule(parent=state2.mols[1], smiles=smiles) for smiles in ["N#Cc1cccc(N)c1F", "O=C(Cl)c1ccc(F)cc1"] ] state3.in_stock_list = [True, True] state3.stock = mocker.MagicMock() state3.stock.__contains__.side_effect = [ False, True, False, True, True, True ] state3.score = 0.99 state3.is_solved = True node3 = mocker.MagicMock() node3.parent = node2 node3.state = state3 node2.promising_child.return_value = node3 node2.children.return_value = [node3] return tree, [node1, node2, node3]