{"action":"created","issue":{"url":"https://api.github.com/repos/tsudalab/ChemTS/issues/5","repository_url":"https://api.github.com/repos/tsudalab/ChemTS","labels_url":"https://api.github.com/repos/tsudalab/ChemTS/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/tsudalab/ChemTS/issues/5/comments","events_url":"https://api.github.com/repos/tsudalab/ChemTS/issues/5/events","html_url":"https://github.com/tsudalab/ChemTS/issues/5","id":318349966,"number":5,"title":"How to Generate Molecules?","user":{"login":"ALPHAYA-Japan","id":38783310,"avatar_url":"https://avatars3.githubusercontent.com/u/38783310?v=4","gravatar_id":"","url":"https://api.github.com/users/ALPHAYA-Japan","html_url":"https://github.com/ALPHAYA-Japan","followers_url":"https://api.github.com/users/ALPHAYA-Japan/followers","following_url":"https://api.github.com/users/ALPHAYA-Japan/following{/other_user}","gists_url":"https://api.github.com/users/ALPHAYA-Japan/gists{/gist_id}","starred_url":"https://api.github.com/users/ALPHAYA-Japan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ALPHAYA-Japan/subscriptions","organizations_url":"https://api.github.com/users/ALPHAYA-Japan/orgs","repos_url":"https://api.github.com/users/ALPHAYA-Japan/repos","events_url":"https://api.github.com/users/ALPHAYA-Japan/events{/privacy}","received_events_url":"https://api.github.com/users/ALPHAYA-Japan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-04-27T10:01:25Z","updated_at":"2018-04-30T07:12:00Z","closed_at":null,"author_association":"NONE","body":"Hi, after saving the model in train_RNN.py,\r\nI loaded the model using `model_from_json(\"model.json\")` and `model.load_weights(\"model.h5\")`\r\n\r\nI called the generate_smile(model,'CCCC')\r\nI got the following error:\r\n\r\n`ValueError: substring not found`\r\n\r\nWhat's wrong with my generate_smile()?"},"comment":{"url":"https://api.github.com/repos/tsudalab/ChemTS/issues/comments/385326261","html_url":"https://github.com/tsudalab/ChemTS/issues/5#issuecomment-385326261","issue_url":"https://api.github.com/repos/tsudalab/ChemTS/issues/5","id":385326261,"user":{"login":"ALPHAYA-Japan","id":38783310,"avatar_url":"https://avatars3.githubusercontent.com/u/38783310?v=4","gravatar_id":"","url":"https://api.github.com/users/ALPHAYA-Japan","html_url":"https://github.com/ALPHAYA-Japan","followers_url":"https://api.github.com/users/ALPHAYA-Japan/followers","following_url":"https://api.github.com/users/ALPHAYA-Japan/following{/other_user}","gists_url":"https://api.github.com/users/ALPHAYA-Japan/gists{/gist_id}","starred_url":"https://api.github.com/users/ALPHAYA-Japan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ALPHAYA-Japan/subscriptions","organizations_url":"https://api.github.com/users/ALPHAYA-Japan/orgs","repos_url":"https://api.github.com/users/ALPHAYA-Japan/repos","events_url":"https://api.github.com/users/ALPHAYA-Japan/events{/privacy}","received_events_url":"https://api.github.com/users/ALPHAYA-Japan/received_events","type":"User","site_admin":false},"created_at":"2018-04-30T07:12:00Z","updated_at":"2018-04-30T07:12:00Z","author_association":"NONE","body":"@yangxiufengsia \r\nThanks for the great help. It WORKED!\r\nHowever, I modified your code as follows, there were some minor mistakes that I tried to correct them:\r\n\r\n```\r\nimport sys\r\nimport math\r\nimport random\r\nimport numpy as np\r\nimport random as pr\r\nfrom rdkit import Chem\r\nfrom make_smile import *\r\nfrom keras.models import load_model\r\nfrom keras.preprocessing import sequence\r\n\r\n\r\ndef chem_kn_simulation(model,state,val):\r\n    max_len = 81\r\n    get_int = [val.index(state[j]) for j in range(len(state))]\r\n    x       = np.reshape(get_int,(1,len(get_int)))\r\n    x_pad   = sequence.pad_sequences(x, maxlen = max_len, dtype = 'int32', padding = 'post', truncating = 'pre', value = 0.0)\r\n\r\n    while not get_int[-1] == val.index(\"\\n\"):\r\n        predictions   = model.predict(x_pad)\r\n        #print(\"shape of RNN\",predictions.shape)\r\n        a             = predictions[0][len(get_int) - 1]\r\n        preds         = np.asarray(a).astype('float64')\r\n        # preds         = np.log(preds) / 1.0\r\n        # preds         = np.exp(preds)\r\n        preds         = preds / np.sum(preds)\r\n        next_probas   = np.random.multinomial(1, preds, 1)\r\n        next_int      = np.argmax(next_probas)\r\n        next_int_test = sorted(range(len(a)), key = lambda i: a[i])[-10:]\r\n        get_int.append(next_int)\r\n        x             = np.reshape(get_int,(1,len(get_int)))\r\n        x_pad         = sequence.pad_sequences(x, maxlen = max_len, dtype = 'int32', padding='post', truncating='pre', value=0.0)\r\n        if len(get_int) > max_len:\r\n            break\r\n\r\n    # print([get_int])\r\n    return [get_int]\r\n\r\n\r\ndef predict_smile(all_posible,val):\r\n    new_compound = []\r\n    for i in range(len(all_posible)):\r\n        generate_smile  = [val[all_posible[i][j]] for j in range(len(all_posible[i])-1)]\r\n        # generate_smile.remove(\"&\")\r\n        new_compound.append(generate_smile)\r\n\r\n    return new_compound\r\n\r\n\r\ndef make_input_smile(generate_smile):\r\n    new_compound = []\r\n    for i in range(len(generate_smile)):\r\n        middle = [generate_smile[i][j] for j in range(len(generate_smile[i]))]\r\n        com    = ''.join(middle)\r\n        new_compound.append(com)\r\n\r\n    return new_compound\r\n\r\n\r\n### Example of using the above three functions to generate molecules\r\nval = [ '\\n', '&','C', '(', ')', 'c', '1', '2', 'o', '=', 'O', 'N', '3', 'F',\r\n        '[C@@H]', 'n', '-', '#', 'S', 'Cl', '[O-]', '[C@H]', '[NH+]', '[C@]',\r\n        's', 'Br', '/', '[nH]', '[NH3+]', '4', '[NH2+]', '[C@@]', '[N+]',\r\n        '[nH+]', '\\\\', '[S@]', '5', '[N-]', '[n+]', '[S@@]', '[S-]', '6', '7',\r\n        'I', '[n-]', 'P', '[OH+]', '[NH-]', '[P@@H]', '[P@@]', '[PH2]',\r\n        '[P@]', '[P+]', '[S+]', '[o+]', '[CH2-]', '[CH-]', '[SH+]', '[O+]',\r\n        '[s+]', '[PH+]', '[PH]', '8', '[S@@+]']\r\n\r\nif __name__ == \"__main__\":\r\n    smiles         = sys.argv[2]\r\n    _, all_smile = zinc_processed_with_bracket([smiles])\r\n    all_smile[0].remove('&')\r\n    all_smile[0].remove('\\n')\r\n    print(all_smile[0])\r\n    model          = load_model(sys.argv[1])\r\n    all_posible    = chem_kn_simulation(model,all_smile[0],val)\r\n    # all_posible    = chem_kn_simulation(model,['C','O','C'],val)\r\n    generate_smile = predict_smile(all_posible,val)\r\n    new_compound = make_input_smile(generate_smile)\r\n\r\n    print(new_compound)\r\n```\r\n"}}
{"actor":{"display_login":"ALPHAYA-Japan"}}