File: RascalMCESTest.cs

package info (click to toggle)
rdkit 202503.6-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 222,000 kB
  • sloc: cpp: 411,111; python: 78,482; ansic: 26,181; java: 8,285; javascript: 4,404; sql: 2,393; yacc: 1,626; lex: 1,267; cs: 1,090; makefile: 581; xml: 229; fortran: 183; sh: 121
file content (143 lines) | stat: -rw-r--r-- 4,586 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//
//  Copyright (C) 2020 Gareth Jones, Glysade LLC
//
//   @@ All Rights Reserved @@
//  This file is part of the RDKit.
//  The contents are covered by the terms of the BSD license
//  which is included in the file license.txt, found at the root
//  of the RDKit source tree.
//

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using GraphMolWrap;
using Xunit;

namespace RdkitTests;

public class RascalMCESTest
{
    [Fact]
    public void TestTestosteroneVsEstradiol()
    {
        var m1 = RWMol.MolFromSmiles("CC12CCC3C(C1CCC2O)CCC4=CC(=O)CCC34C");
        Assert.NotNull(m1);
        var m2 = RWMol.MolFromSmiles("CC12CCC3C(C1CCC2O)CCC4=C3C=CC(=C4)O");
        Assert.NotNull(m2);

        var options = new RascalOptions();
        options.similarityThreshold = 0.6;
        var results = RDKFuncs.rascalMCES(m1, m2, options);
        Assert.Equal(1, results.Count);
        var result = results.First();
        var expectedBondMatches = new List<Tuple<int, int>>
        {
            (0, 0).ToTuple(),
            (1, 1).ToTuple(),
            (2, 2).ToTuple(),
            (3, 3).ToTuple(),
            (4, 4).ToTuple(),
            (5, 5).ToTuple(),
            (6, 6).ToTuple(),
            (7, 7).ToTuple(),
            (8, 8).ToTuple(),
            (9, 9).ToTuple(),
            (10, 10).ToTuple(),
            (11, 11).ToTuple(),
            (12, 12).ToTuple(),
            (20, 19).ToTuple(),
            (21, 20).ToTuple(),
            (22, 21).ToTuple()
        };
        var bondMatches = result.getBondMatches().ToList();
        Assert.Equal(16, bondMatches.Count);
        for (int i = 0; i < 16; i++)
        {
            Assert.Equal(expectedBondMatches[i].Item1, bondMatches[i].first);
            Assert.Equal(expectedBondMatches[i].Item2, bondMatches[i].second);
        }

        Assert.Equal(0.4966, result.getSimilarity(), 4);
        var queryMol = RWMol.MolFromSmarts(result.getSmarts());
        Assert.True(m1.hasSubstructMatch(queryMol));
        Assert.True(m2.hasSubstructMatch(queryMol));
    }

    [Fact(Skip = "Works but takes a long time")]
    public void TestRascalCluster()
    {
        var fileName =
            Path.Combine(Environment.GetEnvironmentVariable("RDBASE"),
                "Code", "GraphMol", "RascalMCES", "data", "chembl_1907596.smi");
        var supplier = new SmilesMolSupplier(fileName, "\t", 1, 0, false);
        var molecules = new ROMol_Vect();
        while (!supplier.atEnd())
        {
            molecules.Add(supplier.next());
        }

        var clusterOptions = new RascalClusterOptions();
        clusterOptions.similarityCutoff = 0.7;
        var clusters = RascalApp.RascalCluster(molecules, clusterOptions);

        Assert.Equal(21, clusters.Count);
        var expectedClusterSizes = new[]
        {
            342, 71, 64, 33, 23, 11, 10, 6, 6, 5, 5,
            4, 3, 3, 3, 3, 3, 2, 2, 2, 14
        };
        for (int i = 0; i < 21; i++)
        {
            Assert.Equal(expectedClusterSizes[i], clusters[i].Count);
        }
    }

    [Fact]
    public void TestSmallButina()
    {
        var fileName =
            Path.Combine(Environment.GetEnvironmentVariable("RDBASE"), "Contrib", "Fastcluster", "cdk2.smi");
        var supplier = new SmilesMolSupplier(fileName, "\t", 1, 0, false);
        var molecules = new ROMol_Vect();
        while (!supplier.atEnd())
        {
            molecules.Add(supplier.next());
        }

        var clusters = RascalApp.RascalButinaCluster(molecules);

        Assert.Equal(29, clusters.Count);
        var expectedClusterSizes = new[]
        {
            6, 6, 6, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
            1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
        };
        for (int i = 0; i < 29; i++)
        {
            Assert.Equal(expectedClusterSizes[i], clusters[i].Count);
        }
    }

    [Fact]
    public void TestSmall()
    {
        var fileName =
            Path.Combine(Environment.GetEnvironmentVariable("RDBASE"), "Contrib", "Fastcluster", "cdk2.smi");
        var supplier = new SmilesMolSupplier(fileName, "\t", 1, 0, false);
        var molecules = new ROMol_Vect();
        while (!supplier.atEnd())
        {
            molecules.Add(supplier.next());
        }

        var clusters = RascalApp.RascalCluster(molecules);
        Assert.Equal(8, clusters.Count);
        var expectedClusterSizes = new[] { 7, 7, 6, 2, 2, 2, 2, 20 };
        for (int i = 0; i < 8; i++)
        {
            Assert.Equal(expectedClusterSizes[i], clusters[i].Count);
        }
    }
}