SET rdkit.ignore_reaction_agents=false;
SET rdkit.agent_FP_bit_ratio=0.2;
SET rdkit.difference_FP_weight_agents=1;
SET rdkit.difference_FP_weight_nonagents=10;
SET rdkit.move_unmmapped_reactants_to_agents=true;
SET rdkit.threshold_unmapped_reactant_atoms=0.2;
SET rdkit.init_reaction=true;
SELECT reaction_from_smiles('c1ccccc1>>c1cccnc1');
 reaction_from_smiles 
----------------------
 c1ccccc1>>c1ccncc1
(1 row)

SELECT reaction_from_smiles('c1ccccc1>CC(=O)O>c1cccnc1');
   reaction_from_smiles    
---------------------------
 c1ccccc1>CC(=O)O>c1ccncc1
(1 row)

SELECT reaction_from_smarts('[c1:1][c:2][c:3][c:4]c[c1:5]>CC(=O)O>[c1:1][c:2][c:3][c:4]n[c1:5]');
                              reaction_from_smarts                               
---------------------------------------------------------------------------------
 c([cH:4][cH:3][cH:2][cH2:1])[cH2:5]>CC(=O)O>n([cH:4][cH:3][cH:2][cH2:1])[cH2:5]
(1 row)

SELECT reaction_from_smarts('C(F)(F)F.[c1:1][c:2][c:3][c:4]c[c1:5]>CC(=O)O>[c1:1][c:2][c:3][c:4]n[c1:5]');
                                  reaction_from_smarts                                  
----------------------------------------------------------------------------------------
 c([cH:4][cH:3][cH:2][cH2:1])[cH2:5]>CC(=O)O.FC(F)F>n([cH:4][cH:3][cH:2][cH2:1])[cH2:5]
(1 row)

SELECT reaction_from_smarts('c1ccc[n,c]c1>>c1nccnc1');
 reaction_from_smarts 
----------------------
 c1ccncc1>>c1cnccn1
(1 row)

SELECT reaction_to_smiles(reaction_from_smiles('c1ccccc1>>c1cccnc1'));
 reaction_to_smiles 
--------------------
 c1ccccc1>>c1ccncc1
(1 row)

SELECT reaction_to_smiles(reaction_from_smarts('c1ccc[n,c]c1>>c1nccnc1'));
 reaction_to_smiles 
--------------------
 c1ccncc1>>c1cnccn1
(1 row)

SELECT reaction_to_smarts(reaction_from_smarts('c1ccc[n,c]c1>>c1nccnc1'));
                     reaction_to_smarts                     
------------------------------------------------------------
 c1:,-c:,-c:,-c:,-[n,c]:,-c:,-1>>c1:,-n:,-c:,-c:,-n:,-c:,-1
(1 row)

SELECT reaction_to_smarts('c1cccnc1>>c1nccnc1'::reaction);
                         reaction_to_smarts                         
--------------------------------------------------------------------
 [#6]1:[#6]:[#6]:[#6]:[#7]:[#6]:1>>[#6]1:[#7]:[#6]:[#6]:[#7]:[#6]:1
(1 row)

SELECT reaction_to_ctab(reaction_from_smiles('c1ccccc1>>c1cccnc1'));
                           reaction_to_ctab                            
-----------------------------------------------------------------------
 $RXN                                                                 +
                                                                      +
       RDKit                                                          +
                                                                      +
   1  1                                                               +
 $MOL                                                                 +
                                                                      +
      RDKit                                                           +
                                                                      +
   6  6  0  0  0  0  0  0  0  0999 V2000                              +
     0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0+
     0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0+
     0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0+
     0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0+
     0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0+
     0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0+
   1  2  4  0                                                         +
   2  3  4  0                                                         +
   3  4  4  0                                                         +
   4  5  4  0                                                         +
   5  6  4  0                                                         +
   6  1  4  0                                                         +
 M  END                                                               +
 $MOL                                                                 +
                                                                      +
      RDKit                                                           +
                                                                      +
   6  6  0  0  0  0  0  0  0  0999 V2000                              +
     0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0+
     0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0+
     0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0+
     0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0+
     0.0000    0.0000    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0+
     0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0+
   1  2  4  0                                                         +
   2  3  4  0                                                         +
   3  4  4  0                                                         +
   4  5  4  0                                                         +
   5  6  4  0                                                         +
   6  1  4  0                                                         +
 M  END                                                               +
 
(1 row)

SELECT reaction_numreactants(reaction_from_smiles('[Cl].c1ccccc1>>c1cccnc1.[OH2]'));
 reaction_numreactants 
-----------------------
                     2
(1 row)

SELECT reaction_numproducts(reaction_from_smiles('[Cl].c1ccccc1>>c1cccnc1.[OH2]'));
 reaction_numproducts 
----------------------
                    2
(1 row)

SELECT reaction_numagents(reaction_from_smiles('[Cl].c1ccccc1>CC(=O)O.[Na+]>c1cccnc1.[OH2]'));
 reaction_numagents 
--------------------
                  2
(1 row)

SELECT reaction_numagents(reaction_from_smarts('C(F)(F)F.[c1:1][c:2][c:3][c:4]c[c1:5]>CC(=O)O>[c1:1][c:2][c:3][c:4]n[c1:5]'));
 reaction_numagents 
--------------------
                  2
(1 row)

SET rdkit.move_unmmapped_reactants_to_agents=false;
SELECT reaction_numagents(reaction_from_smarts('C(F)(F)F.[c1:1][c:2][c:3][c:4]c[c1:5]>CC(=O)O>[c1:1][c:2][c:3][c:4]n[c1:5]'));
 reaction_numagents 
--------------------
                  1
(1 row)

SET rdkit.move_unmmapped_reactants_to_agents=true;
SET rdkit.threshold_unmapped_reactant_atoms=0.9;
SELECT reaction_numagents(reaction_from_smarts('C(F)(F)F.[c1:1][c:2][c:3][c:4]c[c1:5]>CC(=O)O>[c1:1][c:2][c:3][c:4]n[c1:5]'));
 reaction_numagents 
--------------------
                  3
(1 row)

SET rdkit.threshold_unmapped_reactant_atoms=0.2;
SELECT 'c1ccccc1>>c1cccnc1'::reaction @= 'c1ccccc1>>c1cccnc1'::reaction;
 ?column? 
----------
 t
(1 row)

SELECT 'c1ccccc1>>c1cccnc1'::reaction @= 'c1ccccc1>>c1cncnc1'::reaction;
 ?column? 
----------
 f
(1 row)

SELECT reaction_from_ctab('$RXN                                                                 
                                                                     
      RDKit                                                          
                                                                     
  1  1                                                               
$MOL                                                                 
                                                                     
     RDKit                                                           
                                                                     
  6  6  0  0  0  0  0  0  0  0999 V2000                              
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  4  0                                                         
  2  3  4  0                                                         
  3  4  4  0                                                         
  4  5  4  0                                                         
  5  6  4  0                                                         
  6  1  4  0                                                         
M  END                                                               
$MOL                                                                 
                                                                     
     RDKit                                                           
                                                                     
  6  6  0  0  0  0  0  0  0  0999 V2000                              
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  4  0                                                         
  2  3  4  0                                                         
  3  4  4  0                                                         
  4  5  4  0                                                         
  5  6  4  0                                                         
  6  1  4  0                                                         
M  END');
 reaction_from_ctab 
--------------------
 c1ccccc1>>c1ccncc1
(1 row)

CREATE TABLE tmp (id integer, tmprxn text);
\copy tmp from 'data/reaction_test_data.out.rsmi';
select * into pgreactions from (select id,reaction_from_smiles(tmprxn::cstring) rxn from tmp) as r where r is not null;
SET rdkit.move_unmmapped_reactants_to_agents=false;
select * into pgreactions_unchanged from (select id,reaction_from_smiles(tmprxn::cstring) rxn from tmp) as r where r is not null;
DROP table tmp;
SET rdkit.move_unmmapped_reactants_to_agents=true;
SELECT count(*) FROM pgreactions;
 count 
-------
  1000
(1 row)

SELECT count(*) FROM pgreactions_unchanged;
 count 
-------
  1000
(1 row)

SELECT SUM(reaction_numreactants(rxn)) FROM pgreactions;
 sum  
------
 1898
(1 row)

SELECT SUM(reaction_numreactants(rxn)) FROM pgreactions_unchanged;
 sum  
------
 3517
(1 row)

SELECT SUM(reaction_numproducts(rxn)) FROM pgreactions;
 sum  
------
 1157
(1 row)

SELECT SUM(reaction_numproducts(rxn)) FROM pgreactions_unchanged;
 sum  
------
 1157
(1 row)

SELECT SUM(reaction_numagents(rxn)) FROM pgreactions;
 sum  
------
 2528
(1 row)

SELECT SUM(reaction_numagents(rxn)) FROM pgreactions_unchanged;
 sum 
-----
 909
(1 row)

CREATE INDEX rxnidx ON pgreactions USING gist(rxn);
SET enable_indexscan=off;
SET enable_bitmapscan=off;
SET enable_seqscan=on;
SELECT count(*) FROM pgreactions WHERE rxn@>'c1ccccc1>>c1ccncc1';
 count 
-------
    47
(1 row)

SELECT count(*) FROM pgreactions WHERE rxn@>'c1cnccc1>>c1ccccc1';
 count 
-------
    50
(1 row)

SELECT count(*) FROM pgreactions WHERE 'c1ccccc1>>c1ccncc1'<@rxn;
 count 
-------
    47
(1 row)

SELECT count(*) FROM pgreactions WHERE 'c1cnccc1>>c1ccccc1'<@rxn;
 count 
-------
    50
(1 row)

SELECT count(*) FROM pgreactions WHERE rxn@>'c1ccccc1>>';
 count 
-------
   667
(1 row)

SELECT count(*) FROM pgreactions WHERE rxn@>'c1cnccc1>>';
 count 
-------
    83
(1 row)

SELECT count(*) FROM pgreactions WHERE 'c1ccccc1>>'<@rxn;
 count 
-------
   667
(1 row)

SELECT count(*) FROM pgreactions WHERE 'c1cnccc1>>'<@rxn;
 count 
-------
    83
(1 row)

SELECT count(*) FROM pgreactions WHERE rxn@>'>>c1ccncc1';
 count 
-------
    79
(1 row)

SELECT count(*) FROM pgreactions WHERE rxn@>'>>c1ccccc1';
 count 
-------
   650
(1 row)

SELECT count(*) FROM pgreactions WHERE '>>c1ccncc1'<@rxn;
 count 
-------
    79
(1 row)

SELECT count(*) FROM pgreactions WHERE '>>c1ccccc1'<@rxn;
 count 
-------
   650
(1 row)

SET enable_indexscan=on;
SET enable_bitmapscan=on;
SET enable_seqscan=off;
SELECT count(*) FROM pgreactions WHERE rxn@>'c1ccccc1>>c1ccncc1';
 count 
-------
    47
(1 row)

SELECT count(*) FROM pgreactions WHERE rxn@>'c1cnccc1>>c1ccccc1';
 count 
-------
    50
(1 row)

SELECT count(*) FROM pgreactions WHERE 'c1ccccc1>>c1ccncc1'<@rxn;
 count 
-------
    47
(1 row)

SELECT count(*) FROM pgreactions WHERE 'c1cnccc1>>c1ccccc1'<@rxn;
 count 
-------
    50
(1 row)

SELECT count(*) FROM pgreactions WHERE rxn@>'c1ccccc1>>';
 count 
-------
   667
(1 row)

SELECT count(*) FROM pgreactions WHERE rxn@>'c1cnccc1>>';
 count 
-------
    83
(1 row)

SELECT count(*) FROM pgreactions WHERE 'c1ccccc1>>'<@rxn;
 count 
-------
   667
(1 row)

SELECT count(*) FROM pgreactions WHERE 'c1cnccc1>>'<@rxn;
 count 
-------
    83
(1 row)

SELECT count(*) FROM pgreactions WHERE rxn@>'>>c1ccncc1';
 count 
-------
    79
(1 row)

SELECT count(*) FROM pgreactions WHERE rxn@>'>>c1ccccc1';
 count 
-------
   650
(1 row)

SELECT count(*) FROM pgreactions WHERE '>>c1ccncc1'<@rxn;
 count 
-------
    79
(1 row)

SELECT count(*) FROM pgreactions WHERE '>>c1ccccc1'<@rxn;
 count 
-------
   650
(1 row)

SELECT count(*) FROM pgreactions WHERE rxn?>'c1ccccc1>>c1ccncc1';
 count 
-------
    47
(1 row)

SELECT count(*) FROM pgreactions WHERE rxn?>'c1cnccc1>>c1ccccc1';
 count 
-------
    50
(1 row)

SELECT count(*) FROM pgreactions WHERE 'c1ccccc1>>c1ccncc1'?<rxn;
 count 
-------
    47
(1 row)

SELECT count(*) FROM pgreactions WHERE 'c1cnccc1>>c1ccccc1'?<rxn;
 count 
-------
    50
(1 row)

SELECT count(*) FROM pgreactions WHERE rxn?>'c1ccccc1>>';
 count 
-------
   667
(1 row)

SELECT count(*) FROM pgreactions WHERE rxn?>'c1cnccc1>>';
 count 
-------
    83
(1 row)

SELECT count(*) FROM pgreactions WHERE 'c1ccccc1>>'?<rxn;
 count 
-------
   667
(1 row)

SELECT count(*) FROM pgreactions WHERE 'c1cnccc1>>'?<rxn;
 count 
-------
    83
(1 row)

SELECT count(*) FROM pgreactions WHERE rxn?>'>>c1ccncc1';
 count 
-------
    79
(1 row)

SELECT count(*) FROM pgreactions WHERE rxn?>'>>c1ccccc1';
 count 
-------
   650
(1 row)

SELECT count(*) FROM pgreactions WHERE '>>c1ccncc1'?<rxn;
 count 
-------
    79
(1 row)

SELECT count(*) FROM pgreactions WHERE '>>c1ccccc1'?<rxn;
 count 
-------
   650
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>>c1ccncc1',1), reaction_difference_fp('c1ccccc1>>c1ccncc1',1));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>>c1ccncc1',1), reaction_difference_fp('c1ncccc1>>c1ncncc1',1));
   tanimoto_sml    
-------------------
 0.636363636363636
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',1), reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',1));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',1), reaction_difference_fp('c1ncccc1>[Na+]>c1ncncc1',1));
   tanimoto_sml    
-------------------
 0.603448275862069
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>>c1ccncc1',2), reaction_difference_fp('c1ccccc1>>c1ccncc1',2));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>>c1ccncc1',2), reaction_difference_fp('c1ncccc1>>c1ncncc1',2));
 tanimoto_sml 
--------------
          0.2
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',2), reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',2));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',2), reaction_difference_fp('c1ncccc1>[Na+]>c1ncncc1',2));
 tanimoto_sml 
--------------
          0.2
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>>c1ccncc1',3), reaction_difference_fp('c1ccccc1>>c1ccncc1',3));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>>c1ccncc1',3), reaction_difference_fp('c1ncccc1>>c1ncncc1',3));
   tanimoto_sml    
-------------------
 0.454545454545455
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',3), reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',3));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',3), reaction_difference_fp('c1ncccc1>[Na+]>c1ncncc1',3));
   tanimoto_sml    
-------------------
 0.447368421052632
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',1), reaction_structural_bfp('c1ccccc1>>c1ccncc1',1));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',1), reaction_structural_bfp('c1ncccc1>>c1ncncc1',1));
   tanimoto_sml    
-------------------
 0.620689655172414
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',1), reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',1));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',1), reaction_structural_bfp('c1ncccc1>[Na+]>c1ncncc1',1));
   tanimoto_sml    
-------------------
 0.514285714285714
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',2), reaction_structural_bfp('c1ccccc1>>c1ccncc1',2));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',2), reaction_structural_bfp('c1ncccc1>>c1ncncc1',2));
   tanimoto_sml    
-------------------
 0.461538461538462
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',2), reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',2));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',2), reaction_structural_bfp('c1ncccc1>[Na+]>c1ncncc1',2));
   tanimoto_sml    
-------------------
 0.461538461538462
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',3), reaction_structural_bfp('c1ccccc1>>c1ccncc1',3));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',3), reaction_structural_bfp('c1ncccc1>>c1ncncc1',3));
   tanimoto_sml    
-------------------
 0.409090909090909
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',3), reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',3));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',3), reaction_structural_bfp('c1ncccc1>[Na+]>c1ncncc1',3));
 tanimoto_sml 
--------------
      0.34375
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',4), reaction_structural_bfp('c1ccccc1>>c1ccncc1',4));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',4), reaction_structural_bfp('c1ncccc1>>c1ncncc1',4));
   tanimoto_sml   
------------------
 0.27710843373494
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',4), reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',4));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',4), reaction_structural_bfp('c1ncccc1>[Na+]>c1ncncc1',4));
   tanimoto_sml    
-------------------
 0.237113402061856
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',5), reaction_structural_bfp('c1ccccc1>>c1ccncc1',5));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',5), reaction_structural_bfp('c1ncccc1>>c1ncncc1',5));
   tanimoto_sml    
-------------------
 0.771428571428571
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',5), reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',5));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',5), reaction_structural_bfp('c1ncccc1>[Na+]>c1ncncc1',5));
   tanimoto_sml    
-------------------
 0.578571428571429
(1 row)

SET rdkit.agent_FP_bit_ratio=0.5;
SET rdkit.difference_FP_weight_agents=-3;
SET rdkit.difference_FP_weight_nonagents=7;
SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>>c1ccncc1',1), reaction_difference_fp('c1ccccc1>>c1ccncc1',1));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>>c1ccncc1',1), reaction_difference_fp('c1ncccc1>>c1ncncc1',1));
   tanimoto_sml    
-------------------
 0.636363636363636
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',1), reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',1));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',1), reaction_difference_fp('c1ncccc1>[Na+]>c1ncncc1',1));
   tanimoto_sml    
-------------------
 0.515789473684211
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>>c1ccncc1',2), reaction_difference_fp('c1ccccc1>>c1ccncc1',2));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>>c1ccncc1',2), reaction_difference_fp('c1ncccc1>>c1ncncc1',2));
 tanimoto_sml 
--------------
          0.2
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',2), reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',2));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',2), reaction_difference_fp('c1ncccc1>[Na+]>c1ncncc1',2));
 tanimoto_sml 
--------------
          0.2
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>>c1ccncc1',3), reaction_difference_fp('c1ccccc1>>c1ccncc1',3));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>>c1ccncc1',3), reaction_difference_fp('c1ncccc1>>c1ncncc1',3));
   tanimoto_sml    
-------------------
 0.454545454545455
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',3), reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',3));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',3), reaction_difference_fp('c1ncccc1>[Na+]>c1ncncc1',3));
   tanimoto_sml   
------------------
 0.41304347826087
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',1), reaction_structural_bfp('c1ccccc1>>c1ccncc1',1));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',1), reaction_structural_bfp('c1ncccc1>>c1ncncc1',1));
   tanimoto_sml    
-------------------
 0.620689655172414
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',1), reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',1));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',1), reaction_structural_bfp('c1ncccc1>[Na+]>c1ncncc1',1));
   tanimoto_sml    
-------------------
 0.514285714285714
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',2), reaction_structural_bfp('c1ccccc1>>c1ccncc1',2));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',2), reaction_structural_bfp('c1ncccc1>>c1ncncc1',2));
   tanimoto_sml    
-------------------
 0.444444444444444
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',2), reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',2));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',2), reaction_structural_bfp('c1ncccc1>[Na+]>c1ncncc1',2));
   tanimoto_sml    
-------------------
 0.444444444444444
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',3), reaction_structural_bfp('c1ccccc1>>c1ccncc1',3));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',3), reaction_structural_bfp('c1ncccc1>>c1ncncc1',3));
   tanimoto_sml    
-------------------
 0.428571428571429
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',3), reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',3));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',3), reaction_structural_bfp('c1ncccc1>[Na+]>c1ncncc1',3));
   tanimoto_sml    
-------------------
 0.366666666666667
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',4), reaction_structural_bfp('c1ccccc1>>c1ccncc1',4));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',4), reaction_structural_bfp('c1ncccc1>>c1ncncc1',4));
   tanimoto_sml    
-------------------
 0.285714285714286
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',4), reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',4));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',4), reaction_structural_bfp('c1ncccc1>[Na+]>c1ncncc1',4));
   tanimoto_sml    
-------------------
 0.244897959183673
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',5), reaction_structural_bfp('c1ccccc1>>c1ccncc1',5));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',5), reaction_structural_bfp('c1ncccc1>>c1ncncc1',5));
   tanimoto_sml    
-------------------
 0.778846153846154
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',5), reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',5));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',5), reaction_structural_bfp('c1ncccc1>[Na+]>c1ncncc1',5));
   tanimoto_sml   
------------------
 0.58695652173913
(1 row)

SET rdkit.ignore_reaction_agents=true;
SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>>c1ccncc1',1), reaction_difference_fp('c1ccccc1>>c1ccncc1',1));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>>c1ccncc1',1), reaction_difference_fp('c1ncccc1>>c1ncncc1',1));
   tanimoto_sml    
-------------------
 0.636363636363636
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',1), reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',1));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_difference_fp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',1), reaction_difference_fp('c1ncccc1>[Na+]>c1ncncc1',1));
   tanimoto_sml    
-------------------
 0.636363636363636
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',5), reaction_structural_bfp('c1ccccc1>>c1ccncc1',5));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>>c1ccncc1',5), reaction_structural_bfp('c1ncccc1>>c1ncncc1',5));
   tanimoto_sml    
-------------------
 0.778846153846154
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',5), reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',5));
 tanimoto_sml 
--------------
            1
(1 row)

SELECT tanimoto_sml(reaction_structural_bfp('c1ccccc1>CC(=O)O.[Na+]>c1ccncc1',5), reaction_structural_bfp('c1ncccc1>[Na+]>c1ncncc1',5));
   tanimoto_sml    
-------------------
 0.778846153846154
(1 row)

SET enable_indexscan=on;
SET enable_bitmapscan=on;
SET enable_seqscan=on;
DROP INDEX rxnidx;
