Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff #8

Merged
merged 12 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Format Code

on:
push:
branches:
- ruff
- master

jobs:
format:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install dependencies
run: pip install ruff

- name: Check code with ruff
run: ruff check .

- name: Format code with ruff
run: ruff format .
137 changes: 137 additions & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Developer Guide

## Installation

### Prerequisites

rdkit, numpy, pyside2 are installed by default.
ruff is installed using the dev tag as described below

### Installation Steps

1. Clone the repository:

```bash
git clone https://github.com/EBjerrum/rdeditor.git
```

2. Navigate to the project directory:

```bash
cd rdeditor
```

3. Install rdeditor in editable mode to enable developer modifications:

```bash
pip install -e .[dev]
```

4. Optionally, set up your preferred code editor (e.g., VS Code) to format code on save using ruff.

## Automatic Code Formatting with Ruff

The `rdeditor` project utilizes `ruff` as both a linter and code formatter to ensure consistent code quality and formatting standards. You can automate the code formatting process by setting up a pre-commit hook in your local Git repository or configuring VS Code to auto-format code on save using the provided `ruff.toml` specifications.

### Creating a Pre-Commit Hook

You can set up a pre-commit hook in your local Git repository to automatically format code using `ruff` before each commit. Here's how to do it:

1. Navigate to the `.git/hooks` directory in your repository.

2. Create a new file named `pre-commit` if it doesn't already exist.

3. Open the `pre-commit` file in a text editor and add the following content:

```bash
#!/bin/bash

# Run the ruff formatter on staged changes
ruff format $(git diff --cached --name-only | grep '\.py$')

# Stage the formatted changes
git add $(git diff --cached --name-only)
```

4.

5. Save the file and make it executable by running the following command in your terminal:

```bash
chmod +x .git/hooks/pre-commit
```

Now, each time you attempt to commit changes, the `pre-commit` hook will run the `ruff` formatter on your staged changes, ensuring consistent formatting before the commit is finalized.

### Configuring VS Code for Auto-Formatting on Save

If you prefer to use VS Code, you can configure it to automatically format code using the provided `ruff.toml` specifications on save. Here's how to do it:

1. Open VS Code and navigate to the settings by clicking on the gear icon in the bottom left corner or by pressing `Ctrl + ,`.

2. In the search bar at the top, type "format on save" to find the setting.

3. Check the box next to "Editor: Format On Save" to enable auto-formatting on save.

4. Next, click on "Extensions" in the sidebar and search for "ruff" in the search bar.

5. Install the ruff extension.

6. Press `ctrl-shift-p` or select `format with...` from the right click menu in a python file. Select the option `configure default formatter...` and choose ruff.

With these settings configured, VS Code will automatically format your Python code according to the specifications provided in the `ruff.toml` file each time you save a file.

## Usage

[Include usage instructions here if different from README.md]

## Contributing

## Checking code with ruff

Code submitted to github master branch are checked with ruff via GitHub Actions. It is thus advisable to check yourself before a pull request is made. This can be done with:

`ruff check` which will inspect the code and print a list of issues.

Sometimes they can be safely fixed with

`ruff check --fix` and even `ruff check --fix --unsafe-fixes` but otherwise they need to be inspected and mitigated.

### Development Environment Setup

1. Follow the installation steps in the INSTALL section.
2. Set up your preferred code editor (e.g., VS Code) to format code on save.
3. Optionally, configure a pre-commit hook locally to ensure code consistency before committing changes.

### Branching Strategy

- Use meaningful branch names for new features, bug fixes, or enhancements (e.g., feature/add-new-tool, fix/issue-123).
- Create feature branches from the main branch and submit pull requests for review.
- Review and address any feedback from maintainers before merging changes.

### Code Guidelines

- Follow the project's coding standards and style guide.
- Write clear, concise, and well-documented code.
- Include relevant comments and docstrings to explain complex logic or functionality.
- Write meaningful commit messages that describe the purpose of the changes.

## Testing

[Include testing instructions and guidelines here if applicable]

## Troubleshooting

[Include troubleshooting tips and common issues here]

## Additional Resources

[Include links to relevant documentation, tutorials, or external resources]

## Contact

[Provide contact information for project maintainers or contributors]

## Changelog

[Include a summary of recent changes, improvements, and bug fixes]
56 changes: 32 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# rdeditor

Simple RDKit molecule editor GUI using PySide2
![rdeditor, the RDKit molecule editor](./Screenshots/Main_window.png)

## Installation
* requirements

RDKIT and PySide
- requirements

RDKit, NumPy and PySide2 should be automatically pip installed by the setup.py script.

- installation

* installation
```bash
python setup.py install

Expand All @@ -16,51 +19,56 @@ python setup.py install
The install script Will also install PySide2, but not RDkit, so that should be installed manually or via your operating systems package manager. A launch script will also be added so that it can be started from the command line via the rdEditor command.

## Alternative install
Install PySide and RDKit yourself, save the content of rdeditor folder to somewhere you like and start it with

Install PySide and RDKit yourself, save the content of rdeditor folder to somewhere you like and start it with
`python rdEditor.py`

## Usage

Can be started with `rdEditor` or `rdEditor your_molecule.mol` to start edit an existing molecule.
Interactions with the molecule are done via clicking on the canvas, atoms or bonds. A choice of tools is available.

#### Top Menu:
#### Top Menu:

![top menu of rdeditor, the RDKit molecule editor](./Screenshots/Top_Menu.png)

From left to right
* Open: Open a molfile
* Save: Save current molecule
* Save As: Save current molecule with a new name


* Arrow: Select tool. Click on an atom to select it, click on the canvas to deselect. Clicking on multiple atoms one after another will select them, but only the lastly clicked one will be highlighted in red and used for operations, such as bond creation to another existing atom.
* Pen: Add tool. Clicking on an existing atom will add the current selected atom type to that atom with a single bond. Clicking on the canvas will add a disconnected atom. Clicking on a bond will cycle through single, double and triple bonds.
* Add bond / Join atoms: Will add a single bond between a clicked atom (or a previously selected atom) and the next atom clicked.
* Change Atom: Will substitute the atom clicked, with the currently selected atom type
* R/S: Change the stereo chemistry of the selected atom (see issues below)
* E/Z: Change E/Z stereo of double bonds (see issues below)
* Increase/Decrease charge: Will increase or decrease the charge of the atom clicked
* Delete atom/bond:
* Clear Canvas
* Undo.

- Open: Open a molfile
- Save: Save current molecule
- Save As: Save current molecule with a new name

- Arrow: Select tool. Click on an atom to select it, click on the canvas to deselect. Clicking on multiple atoms one after another will select them, but only the lastly clicked one will be highlighted in red and used for operations, such as bond creation to another existing atom.
- Pen: Add tool. Clicking on an existing atom will add the current selected atom type to that atom with a single bond. Clicking on the canvas will add a disconnected atom. Clicking on a bond will cycle through single, double and triple bonds.
- Add bond / Join atoms: Will add a single bond between a clicked atom (or a previously selected atom) and the next atom clicked.
- Change Atom: Will substitute the atom clicked, with the currently selected atom type
- R/S: Change the stereo chemistry of the selected atom (see issues below)
- E/Z: Change E/Z stereo of double bonds (see issues below)
- Increase/Decrease charge: Will increase or decrease the charge of the atom clicked
- Delete atom/bond:
- Clear Canvas
- Undo.

#### Side Bar:

![top menu of rdeditor, the RDKit molecule editor](./Screenshots/Side_bar.png)

Most commonly used bond types, and atom types can be selected. A Periodic table is accessible for exotic atom types.

#### Dropdown menus

Access to all standard operations as well as less used atom types and bond-types.

## Additional Reading

I wrote a blog post with an overview of the structure of the code.
[https://www.wildcardconsulting.dk/rdeditor-an-open-source-molecular-editor-based-using-python-pyside2-and-rdkit/](https://www.wildcardconsulting.dk/rdeditor-an-open-source-molecular-editor-based-using-python-pyside2-and-rdkit/)

We also published a preprint on ChemRxiv: [https://chemrxiv.org/engage/chemrxiv/article-details/65e6dcfa9138d23161b2979c](https://chemrxiv.org/engage/chemrxiv/article-details/65e6dcfa9138d23161b2979c)

## ISSUES
* Not possible to set undefined R/S (no wiggly bond rendered)
* Not possible to distinguish undefined and trans when editing cis/trans double bonds
* Aromaticity perception hides double-single bonds (kekulization can do likewise)
* Molecule jumping now more limited, but atom placement may not be optimal as rest og structure kept fixed (and ignored?)

- Not possible to set undefined R/S (no wiggly bond rendered)
- Not possible to distinguish undefined and trans when editing cis/trans double bonds
- Aromaticity perception hides double-single bonds (kekulization can do likewise)
- Molecule jumping now more limited, but atom placement may not be optimal as rest og structure kept fixed (and ignored?)
13 changes: 5 additions & 8 deletions rdeditor/Mendelev_extract.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from mendeleev import element


elements={}
elements = {}
symboltoint = {}


for i in range(1,119):
e = element(i)
elements[i] = {"Name":e.name, "Symbol":e.symbol,"Group": e.group_id,"Period":e.period}
symboltoint[e.symbol] = i



for i in range(1, 119):
e = element(i)
elements[i] = {"Name": e.name, "Symbol": e.symbol, "Group": e.group_id, "Period": e.period}
symboltoint[e.symbol] = i
7 changes: 3 additions & 4 deletions rdeditor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#from molViewWidget import molViewWidget
#from molEditWidget import MolEditWidget
#from ptable_widget import PTable
# from molViewWidget import molViewWidget
# from molEditWidget import MolEditWidget
# from ptable_widget import PTable
from .rdEditor import MainWindow

Loading