コード例 #1
0
ファイル: test_utils.py プロジェクト: KarelBerka/cmiles
def test_get_atom_map_mapped_smiles(toolkit):
    smiles_1 = '[H]C([H])(C([H])([H])O[H])O[H]'
    smiles_2 = '[H:5][C:1]([H:6])([C:2]([H:7])([H:8])[O:4][H:10])[O:3][H:9]'
    mol_1 = utils.load_molecule(smiles_1, toolkit=toolkit)
    if not utils.has_explicit_hydrogen(mol_1):
        mol_1 = utils.add_explicit_hydrogen(mol_1)
    mol_2 = utils.load_molecule(smiles_2, toolkit=toolkit)
    if not utils.has_explicit_hydrogen(mol_2):
        mol_2 = utils.add_explicit_hydrogen(mol_2)
コード例 #2
0
ファイル: test_utils.py プロジェクト: pk-organics/cmiles
def test_n_valence():
    from openeye import oechem
    json_molecule = {
        'symbols': [
            'C', 'C', 'C', 'C', 'C', 'C', 'N', 'N', 'N', 'N', 'N', 'H', 'H',
            'H', 'H'
        ],
        'geometry':
        np.array([
            11.02088236, 0.30802536, 2.96687012, 10.37270642, 2.8383686,
            2.75522059, 9.32012957, -1.48532476, 2.09948562, 8.06346176,
            3.48843435, 1.68941515, 6.98820713, -0.772898, 1.02801107,
            5.21186447, -2.73065435, 0.12850138, 5.70508328, -5.1797392,
            0.28345893, 6.45152507, 1.7536658, 0.86549457, 2.97820833,
            -2.31491455, -0.90706852, 3.71709131, -6.31357514, -0.68408084,
            2.05980154, -4.57124733, -1.40784597, 12.76887939, -0.24566439,
            3.77189345, 11.61992628, 4.26322222, 3.39583795, 9.76610505,
            -3.43174262, 2.23743576, 7.53811768, 5.41217579, 1.50989122
        ]),
        'connectivity':
        [[0, 1, 1], [0, 2, 2], [0, 11, 1], [1, 3, 2], [1, 12, 1], [2, 4, 1],
         [2, 13, 1], [3, 7, 1], [3, 14, 1], [4, 5, 1], [4, 7, 2], [5, 6, 1],
         [5, 8, 2], [6, 9, 1], [8, 10, 1], [9, 10, 2]]
    }
    mol = utils.load_molecule(json_molecule)
    assert utils.has_explicit_hydrogen(mol)
    assert oechem.OEMolToSmiles(mol) == 'c1ccnc(c1)c2[n-]nnn2'
コード例 #3
0
ファイル: test_utils.py プロジェクト: KarelBerka/cmiles
def test_atom_order_in_mol_copy(toolkit, smiles):
    """Test that atom orders do not change when copying molecule"""
    import copy
    mol = utils.load_molecule(smiles, toolkit=toolkit)
    if not utils.has_explicit_hydrogen(mol):
        mol = utils.add_explicit_hydrogen(mol)
    molcopy = copy.deepcopy(mol)
    for a1, a2 in zip(mol.GetAtoms(), molcopy.GetAtoms()):
        if toolkit == 'openeye':
            assert a1.GetIdx() == a2.GetIdx()
            assert a1.GetName() == a2.GetName()
            assert a1.GetMapIdx() == a2.GetMapIdx()
        if toolkit == 'rdkit':
            assert a1.GetIdx() == a2.GetIdx()
            assert a1.GetAtomMapNum() == a2.GetAtomMapNum()
            assert a1.GetSmarts() == a2.GetSmarts()
コード例 #4
0
ファイル: test_utils.py プロジェクト: KarelBerka/cmiles
def test_atom_map(smiles):
    """Test that atom map orders geometry the same way every time no matter the SMILES used to create the molecule"""
    import cmiles
    mapped_smiles = '[H:5][C:1]([H:6])([C:2]([H:7])([H:8])[O:4][H:10])[O:3][H:9]'
    mol_id_oe = cmiles.get_molecule_ids(mapped_smiles, toolkit='openeye')
    oemol = utils.load_molecule(mapped_smiles, toolkit='openeye')
    mapped_symbols = ['C', 'C', 'O', 'O', 'H', 'H', 'H', 'H', 'H', 'H']
    mapped_geometry = [
        -1.6887193912042044, 0.8515190939276903, 0.8344587822904272,
        -4.05544806361675, -0.3658269566455062, -0.22848169646448416,
        -1.6111611950422127, 0.4463128276938808, 3.490617694146934,
        -3.97756355964586, -3.0080934853087373, 0.25948499322223956,
        -1.6821252026076652, 2.891135395246369, 0.4936556190978574, 0.0, 0.0,
        0.0, -4.180315034973438, -0.09210893239246959, -2.2748227320305525,
        -5.740516456782416, 0.4115539217904015, 0.6823267491485907,
        -0.07872657410528058, 1.2476492272884379, 4.101615944163073,
        -5.514569080545831, -3.7195945404657222, -0.4441653010509862
    ]

    mol = cmiles.utils.load_molecule(smiles, toolkit='openeye')
    if not utils.has_explicit_hydrogen(mol):
        mol = utils.add_explicit_hydrogen(mol)
    atom_map = utils.get_atom_map(mol, mapped_smiles=mapped_smiles)
    # use the atom map to add coordinates to molecule. First reorder mapped geometry to order in molecule
    mapped_coords = np.array(mapped_geometry, dtype=float).reshape(
        int(len(mapped_geometry) / 3), 3)
    coords = np.zeros((mapped_coords.shape))
    for m in atom_map:
        coords[atom_map[m]] = mapped_coords[m - 1]
    # flatten
    coords = coords.flatten()
    # convert to Angstroms
    coords = coords * utils.BOHR_2_ANGSTROM
    # set coordinates in oemol
    mol.SetCoords(coords)
    mol.SetDimension(3)

    # Get new atom map
    atom_map = utils.get_atom_map(mol, mapped_smiles)
    symbols, geometry = _cmiles_oe.get_map_ordered_geometry(mol, atom_map)
    assert geometry == mapped_geometry
    assert symbols == mapped_symbols
コード例 #5
0
ファイル: test_utils.py プロジェクト: KarelBerka/cmiles
def test_explicit_h_oe(input, output):
    """Test input SMILES for explicit H"""

    mol = utils.load_molecule(input, toolkit='openeye')
    assert utils.has_explicit_hydrogen(mol) == output
コード例 #6
0
ファイル: test_utils.py プロジェクト: KarelBerka/cmiles
def test_explicit_h(input, output, toolkit_name):
    """Test input SMILES for explicit H"""
    mol = utils.load_molecule(input, toolkit=toolkit_name)
    assert utils.has_explicit_hydrogen(mol) == output