Example #1
0
def toStringRep(v):
    """Generate a string representation of a molvector
      :param v: molvector
    """
    p = GetPeriodicTable()
    chunksize = atom_size + bond_chunk_size
    nchunks = len(v) // chunksize
    m = RWMol()
    out = []
    for i in range(nchunks):
        start = i * (atom_size + bond_chunk_size)
        el, c, h, b1, o1, b2, o2, b3, o3, b4, o4 = v[start:start + chunksize]
        el = ("%2s" % p.GetElementSymbol(el)).replace(" ", "_")
        out.append(el)
        assert c < 10
        out.append(str(c))
        assert h < 10
        out.append(str(h))
        for btype, o in ((b1, o1), (b2, o2), (b3, o3), (b4, o4)):
            out.append(bond_symbols[btype])
            out.append("%04d" % o)
    return "".join(out)
Example #2
0
                            help='Path to molecules to use as seeds')

    # Parse the arguments
    args = arg_parser.parse_args()
    run_params = args.__dict__

    # Get the list of elements
    #  We want those where SMILES supports implicit valences
    mpnn_dir = os.path.join('notebooks', 'mpnn-training')
    with open(os.path.join(mpnn_dir, 'atom_types.json')) as fp:
        atom_types = json.load(fp)
    with open(os.path.join(mpnn_dir, 'bond_types.json')) as fp:
        bond_types = json.load(fp)
    pt = GetPeriodicTable()
    if len(args.elements) == 0:
        elements = [pt.GetElementSymbol(i) for i in atom_types]
    else:
        elements = args.elements
    elements = [e for e in elements if MolFromSmiles(e) is not None]
    logger.info(f'Using {len(elements)} elements: {elements}')

    # Prepare the one-shot model. We the molecules to compare against and the comparison model
    with open(os.path.join('seed-molecules', 'top_100_pIC50.json')) as fp:
        comparison_mols = [convert_smiles_to_nx(s) for s in json.load(fp)]
    oneshot_dir = 'similarity'
    oneshot_model = load_model(os.path.join(oneshot_dir, 'oneshot_model.h5'),
                               custom_objects=custom_objects)
    with open(os.path.join(oneshot_dir, 'atom_types.json')) as fp:
        os_atom_types = json.load(fp)
    with open(os.path.join(oneshot_dir, 'bond_types.json')) as fp:
        os_bond_types = json.load(fp)