From ab176926231a858009dbbe5e6fba1a7a8e93edb8 Mon Sep 17 00:00:00 2001 From: James Nelson Date: Mon, 19 Jan 2026 16:55:10 +0000 Subject: [PATCH 1/5] simplify --- qse/qbits.py | 100 +++++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 56 deletions(-) diff --git a/qse/qbits.py b/qse/qbits.py index 7ff6d08..44efc7f 100644 --- a/qse/qbits.py +++ b/qse/qbits.py @@ -7,9 +7,6 @@ import numpy as np from ase.cell import Cell -from ase.geometry import ( - find_mic, -) from qse.qbit import Qbit from qse.visualise import draw as _draw @@ -1085,76 +1082,67 @@ def get_all_distances(self): def set_distance( self, - a0, - a1, + i, + j, distance, fix=0.5, - mic=False, mask=None, indices=None, add=False, factor=False, ): """ - Set the distance between two qbits. + Set the distance between qubits i and j. - Set the distance between qbits *a0* and *a1* to *distance*. - By default, the center of the two qbits will be fixed. Use - *fix=0* to fix the first qbit, *fix=1* to fix the second - qbit and *fix=0.5* (default) to fix the center of the bond. - - If *mask* or *indices* are set (*mask* overwrites *indices*), - only the qbits defined there are moved - (see :meth:`ase.Qbits.set_dihedral`). - - When *add* is true, the distance is changed by the value given. - In combination - with *factor* True, the value given is a factor scaling the distance. - - It is assumed that the qbits in *mask*/*indices* move together - with *a1*. If *fix=1*, only *a0* will therefore be moved.""" + Parameters + ---------- + i : int + The index of the ith qubit. + j : int + The index of the jth qubit. + distance : float + The new distance to be set. + fix : float + By default, the center of the two qbits will be fixed. Use + fix=0 to fix the first qbit, fix=1 to fix the second + qbit and fix=0.5 (default) to fix the center of the bond. + mask: np.ndarray + If mask or indices are set (mask overwrites indices), + only the qbits defined there are moved. It is assumed that the + qbits in mask/indices move together with the jth qubit. + If fix=1, only the ith qubit will therefore be moved. + indices: np.ndarray + If mask or indices are set (mask overwrites indices), + only the qbits defined there are moved. It is assumed that the + qbits in mask/indices move together with the jth qubit. + If fix=1, only the ith qubit will therefore be moved. + add: + When add is true, the distance is changed by the value given. + factor: + When factor is true, the value given is a factor scaling the distance. + """ - if a0 % len(self) == a1 % len(self): - raise ValueError("a0 and a1 must not be the same") + if i % len(self) == j % len(self): + raise ValueError("i and j must not be the same") if add: - oldDist = self.get_distance(a0, a1, mic=mic) - if factor: - newDist = oldDist * distance - else: - newDist = oldDist + distance - self.set_distance( - a0, - a1, - newDist, - fix=fix, - mic=mic, - mask=mask, - indices=indices, - add=False, - factor=False, - ) - return - - R = self.arrays["positions"] - D = np.array([R[a1] - R[a0]]) - - if mic: - D, D_len = find_mic(D, self.cell, self.pbc) - else: - D_len = np.array([np.sqrt((D**2).sum())]) - x = 1.0 - distance / D_len[0] + distance += self.get_distance(i, j) + elif factor: + distance *= self.get_distance(i, j) if mask is None and indices is None: - indices = [a0, a1] + indices = [i, j] elif mask: - indices = [i for i in range(len(self)) if mask[i]] + indices = [ind for ind in range(len(self)) if mask[ind]] + + distance_vec = self.positions[j] - self.positions[i] + x = 1.0 - distance / np.linalg.norm(distance_vec) - for i in indices: - if i == a0: - R[a0] += (x * fix) * D[0] + for ind in indices: + if ind == i: + self.arrays["positions"][ind] += (x * fix) * distance_vec else: - R[i] -= (x * (1.0 - fix)) * D[0] + self.arrays["positions"][ind] -= (x * (1.0 - fix)) * distance_vec def wrap(self, **wrap_kw): """Wrap positions to unit cell. From 6cb8f17fc6fc2240274600ef232b02580fd694ad Mon Sep 17 00:00:00 2001 From: James Nelson Date: Mon, 19 Jan 2026 17:11:23 +0000 Subject: [PATCH 2/5] ignore example --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index dfb75c4..90b3094 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,7 @@ docs = [ [tool.black] line-length = 88 +exclude = 'examples' [tool.mypy] ignore_missing_imports = true From 386f13e6bc5d1737a86a364d840f3b7c9f9e6321 Mon Sep 17 00:00:00 2001 From: James Nelson Date: Mon, 19 Jan 2026 17:14:01 +0000 Subject: [PATCH 3/5] list --- qse/qbits.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qse/qbits.py b/qse/qbits.py index 44efc7f..2ffb974 100644 --- a/qse/qbits.py +++ b/qse/qbits.py @@ -1106,12 +1106,12 @@ def set_distance( By default, the center of the two qbits will be fixed. Use fix=0 to fix the first qbit, fix=1 to fix the second qbit and fix=0.5 (default) to fix the center of the bond. - mask: np.ndarray + mask: np.ndarray | list If mask or indices are set (mask overwrites indices), only the qbits defined there are moved. It is assumed that the qbits in mask/indices move together with the jth qubit. If fix=1, only the ith qubit will therefore be moved. - indices: np.ndarray + indices: np.ndarray | list If mask or indices are set (mask overwrites indices), only the qbits defined there are moved. It is assumed that the qbits in mask/indices move together with the jth qubit. From 4a2799c5593db99e8edb7f78c5b28bb5ee7af8a1 Mon Sep 17 00:00:00 2001 From: James Nelson Date: Tue, 20 Jan 2026 10:51:48 +0000 Subject: [PATCH 4/5] restore pyproject.toml --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 90b3094..dfb75c4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,7 +55,6 @@ docs = [ [tool.black] line-length = 88 -exclude = 'examples' [tool.mypy] ignore_missing_imports = true From 1b444faadd6d96238fd33f11e92a2a09b73dd34e Mon Sep 17 00:00:00 2001 From: James Nelson Date: Fri, 20 Feb 2026 11:45:02 +0000 Subject: [PATCH 5/5] update --- qse/qbits.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qse/qbits.py b/qse/qbits.py index 2ffb974..a6eb2bf 100644 --- a/qse/qbits.py +++ b/qse/qbits.py @@ -1140,9 +1140,9 @@ def set_distance( for ind in indices: if ind == i: - self.arrays["positions"][ind] += (x * fix) * distance_vec + self.positions[ind] += (x * fix) * distance_vec else: - self.arrays["positions"][ind] -= (x * (1.0 - fix)) * distance_vec + self.positions[ind] -= (x * (1.0 - fix)) * distance_vec def wrap(self, **wrap_kw): """Wrap positions to unit cell.