Using PyCharm

PyCharm is a Python IDE by JetBrains available from http://www.jetbrains.com/pycharm.

Create a new project

After successful installation of PyCharm a new project has to be created. If not prompted when opening PyCharm such as in Opening PyCharm a new project can be created via File \(\rightarrow\) New Project… in the main toolbar.

../_images/pycharm-launch.png

Opening PyCharm

Give your project a name such as OESample. Pick a Python interpreter, PyCharm will try to find your Python installation for you. Optionally, pick the location where to save the project to. The dialog should look like PyCharm project dialogue

../_images/pycharm-project.png

PyCharm project dialogue

Adding OpenEye Python package to your project

The next step is to add the OpenEye Python toolkit to this project. Select PyCharm \(\rightarrow\) Preferences.. in the main toolbar then select Project: OESample and Project Interpreter sub-menu to access the PyCharm Preferences dialog box.

../_images/pycharm-preferences.png

PyCharm Preferences

Create a virtual environment by clicking the “…” button on the right as show in PyCharm Preferences and enter the name of your new virtual environment as shown in Create Virtual Environment.

../_images/pycharm-env.png

Create Virtual Environment

After creating the environment, click on the “+” sign at the bottom to access available packages to install see Available Packages.

../_images/pycharm-packages.png

Available Packages

In order to be able to add the OpenEye Python package click on the Manage Repositories at the button and add https://pypi.anaconda.org/OpenEye/simple to the list.

../_images/pycharm-package-repositories.png

Manage Repositories

Back to the Available Packages dialog push the circle arrow at the bottom right in order to reload the available packages and then type “openeye-toolkits” in the text box at the top. Select “openeye-toolkits” meta-package at the top and then push the Install Package button at the bottom as shown in Install OpenEye Package.

../_images/pycharm-openeye-package.png

Install OpenEye Package

After a couple of seconds a message: “Package ‘openeye-toolkits’ installed successfully” will appear at the bottom. Going back to the “Preferences” dialog should look like Successful Installation of OpenEye Package.

../_images/pycharm-openeye-installed.png

Successful Installation of OpenEye Package

Adding a module to your project

With an OpenEye enabled project now an example can be written and tested. First change the view by selecting in the main toolbar View \(\rightarrow\) Tool Windows \(\rightarrow\) Project. Then a new Python module can be created by right clicking on the OESample project (in the list on the right) and then selecting New \(\rightarrow\) Python Package. After naming the project, in this case oechemexamples, a new Python file can be added the newly created package by right clicking on the oechemexamples an then selecting New \(\rightarrow\) Python File. In this case a new example file is created with a name oesample.py and with the following sample code:

from openeye import oechem


def main():
    mol = oechem.OEGraphMol()
    oechem.OEParseSmiles(mol, 'c1ccccc1CCCBr')
    print('mol has {0} atoms'.format(mol.NumAtoms()))

if __name__ == "__main__":
    main()

This new example can be run by right clicking oesample.py and selecting Run ‘oesample’ A run dialog will appear at the bottom of the window with the single print statement and it should look like PyCharm code and run output.

../_images/pycharm-code.png

PyCharm code and run output