analitics

Pages

Saturday, April 11, 2026

Python 3.13.0 : new video with qiskit and Serotonină versus Formaldehidă python script.

I wrote about this python package on my blogs and it is very useful for those who study quantum theory. Today, seeing this video from I.B.M. I decided to see how it works on a particular case, obviously using the Gemini artificial intelligence from Google.
First of all, I was never good at chemistry because I started in elementary school on a different correct informational substrate and it didn't match my math... After academic studies I can now say that the assimilation is different and that's why I took this test with this python package.
About the script I used is an quantum simulation between Serotonină versus Formaldehidă with Hartree energy.
Terminology: It uses standard scientific terms like "Covalent Bond" (the strong link for formaldehyde) and "Signal Transmitted" (the function of serotonin).
The Hartree Energy (Eh) is the atomic unit of energy. It is defined by the energy of an electron in a hydrogen atom in its ground state (technically, it is twice the ionization energy of hydrogen).
Hamiltonian Clarity: clarify that II is the base energy while ZZ and XX represent the quantum correlations between the atoms.
Future-Proofing: By using real_amplitudes (lowercase), the script will remain functional even after Qiskit 3.0 is released and the older RealAmplitudes class is removed.
This script is a Quantum Variational Eigensolver (VQE) simulation designed to calculate the lowest energy state (ground state) of two different molecular interactions.
The Quantum Template Ansatz (QTA) is a specialized strategy used in Variational Quantum Algorithms (VQAs), such as the Variational Quantum Eigensolver (VQE). In simple terms, an "Ansatz" is a mathematical guess or a starting structure.
The SLSQP (Sequential Least Squares Programming) optimizer is one of the most popular "classical" algorithms used in the hybrid quantum-classical loop. It is a gradient-based optimization method designed to solve non-linear programming problems.
What the script does
Defines the Problem - Hamiltonians : It converts chemical data into a "mathematical map" called a Hamiltonian. We used two different maps: one for Formaldehyde to simulating a strong, permanent bond and one for Serotonin to simulating a delicate, temporary signal.
Creates a Quantum Template Ansatz: It builds a quantum circuit (real_amplitudes) that acts as a flexible "key." The algorithm turns the "knobs" (parameters) of this key to find the shape that fits the energy map perfectly.
Finds the Minimum Energy: It uses a classical optimizer (SLSQP) to guide the quantum simulator until the lowest possible energy value is found.
Why you got this specific result
Formaldehyde (-2.7614 Hartree): The energy is very low (negative), which indicates a highly stable and strong "Covalent Bond." In chemistry, the more negative the energy, the harder it is to break that bond. This is why formaldehyde is dangerous—it "locks" onto proteins and doesn't let go.
Serotonin (-1.6942 Hartree): The energy is higher (less negative) than formaldehyde. This represents a "Transient Interaction." It is stable enough to send a signal to your brain, but weak enough to be released later so the receptor can reset.
The 0.01 Hartree Warning: We added a deliberate 0.01 error to simulate the "noise" of a real quantum computer. Because Serotonin's interaction is so delicate, an error of 0.59% is enough to make the simulation unreliable. This highlights why Chemical Accuracy is the biggest challenge in quantum medicine—if our "glasses" (the computer) are even slightly blurry, we cannot correctly predict if a drug will work.
In summary: Your result confirms that Formaldehyde is a permanent "toxin" while Serotonin is a flexible "messenger," and it proves that current quantum simulations need extreme precision to be biologically useful.
The result of the quantum simulation , over the magnitude.These small changes matter. Because a Hartree is such a large unit of energy, researchers often convert the final result into units used in a lab setting. While 74 Hartrees sounds like a lot, chemical reactions happen in the "milli-Hartree" range. See result:
--- QUANTUM SIMULATION INPUT PARAMETERS ---
Formaldehyde Hamiltonian: [('II', -1.8572), ('IZ', 0.45), ('ZI', -0.45), ('ZZ', -0.02), ('XX', 0.21)]
Serotonin    Hamiltonian: [('II', -1.1245), ('IZ', 0.28), ('ZI', -0.28), ('ZZ', -0.01), ('XX', 0.15)]
------------------------------------------------------------

--- QUANTUM ANALYSIS: PROTEIN INTERACTION ---

[FORMALDEHYDE + PROTEIN]
  Ideal Energy: -2.7614 Hartree
  Energy with Noise (0.01): -2.7514 Hartree
  Status: DANGER - Stable Covalent Bond

[SEROTONIN + RECEPTOR]
  Ideal Energy: -1.6942 Hartree
  Energy with Noise (0.01): -1.6842 Hartree
  Status: ACTIVE - Signal Transmitted

============================================================
CONCLUSION ON CHEMICAL ACCURACY:
An error of 0.01 Hartree represents 0.59% of Serotonin's energy.
WARNING: Error exceeds the safety threshold for biological prediction!
============================================================
This is the source code, created by Gemini artificial intelligence and tested by my:
import numpy as np
from qiskit.quantum_info import SparsePauliOp
from qiskit.circuit.library import real_amplitudes
from qiskit.primitives import StatevectorEstimator
from qiskit_algorithms import VQE
from qiskit_algorithms.optimizers import SLSQP

# --- QUANTUM SIMULATION INPUT DATA ---
# Formaldehyde + Protein (Strong Covalent bond simulation)
# High base energy (-1.85) and strong coupling terms
formaldehyde_input = [
    ("II", -1.8572), ("IZ", 0.45), ("ZI", -0.45), ("ZZ", -0.02), ("XX", 0.21)
]

# Serotonin + Receptor (Delicate Neurotransmitter interaction)
# Lower base energy (-1.12) and sensitive correlation terms
serotonin_input = [
    ("II", -1.1245), ("IZ", 0.28), ("ZI", -0.28), ("ZZ", -0.01), ("XX", 0.15)
]

def run_quantum_vqe(input_data):
    """Executes the VQE algorithm using the modern StatevectorEstimator."""
    hamiltonian = SparsePauliOp.from_list(input_data)
    # Using the functional 'real_amplitudes' to avoid Deprecation Warnings
    ansatz = real_amplitudes(num_qubits=2, reps=1)
    estimator = StatevectorEstimator()
    optimizer = SLSQP(maxiter=100)
    
    vqe = VQE(estimator, ansatz, optimizer)
    result = vqe.compute_minimum_eigenvalue(hamiltonian)
    return result.eigenvalue.real

# Execution
print("--- QUANTUM SIMULATION INPUT PARAMETERS ---")
print(f"Formaldehyde Hamiltonian: {formaldehyde_input}")
print(f"Serotonin    Hamiltonian: {serotonin_input}")
print("-" * 60)

# Computing Ideal Energies
ideal_energy_form = run_quantum_vqe(formaldehyde_input)
ideal_energy_sero = run_quantum_vqe(serotonin_input)

# Simulating the Chemical Accuracy Threshold (0.01 Hartree)
chemical_accuracy_threshold = 0.01
noisy_energy_form = ideal_energy_form + chemical_accuracy_threshold
noisy_energy_sero = ideal_energy_sero + chemical_accuracy_threshold

# --- FINAL QUANTUM ANALYSIS OUTPUT ---
print("\n--- QUANTUM ANALYSIS: PROTEIN INTERACTION ---")

print(f"\n[FORMALDEHYDE + PROTEIN]")
print(f"  Ideal Energy: {ideal_energy_form:.4f} Hartree")
print(f"  Energy with Noise (0.01): {noisy_energy_form:.4f} Hartree")
print(f"  Status: {'DANGER - Stable Covalent Bond' if ideal_energy_form < -1.5 else 'Inactive'}")

print(f"\n[SEROTONIN + RECEPTOR]")
print(f"  Ideal Energy: {ideal_energy_sero:.4f} Hartree")
print(f"  Energy with Noise (0.01): {noisy_energy_sero:.4f} Hartree")
print(f"  Status: {'ACTIVE - Signal Transmitted' if ideal_energy_sero < -1.0 else 'Binding Failure'}")

print("\n" + "="*60)
print("CONCLUSION ON CHEMICAL ACCURACY:")
error_percentage = (chemical_accuracy_threshold / abs(ideal_energy_sero)) * 100
print(f"An error of 0.01 Hartree represents {error_percentage:.2f}% of Serotonin's energy.")
if error_percentage > 0.5:
    print("WARNING: Error exceeds the safety threshold for biological prediction!")
print("="*60)

Friday, April 10, 2026

Python Qt : particles with pygame and pyqt6.

Today, I test one python script with pygame and pyqt6. The python script use classes and show particles. See the result:
This is the source code:
import sys
import random
import pygame
from pygame import Vector2
from PyQt6.QtWidgets import (
    QApplication, QWidget, QVBoxLayout, QHBoxLayout,
    QSlider, QLabel, QSizePolicy
)
from PyQt6.QtCore import Qt, QTimer
from PyQt6.QtGui import QImage, QPainter

class Particle:
    def __init__(self, pos, vel, color):
        self.pos = Vector2(pos)
        self.vel = Vector2(vel)
        self.color = color
        self.life = 255

    def update(self, gravity):
        self.vel.y += gravity
        self.pos += self.vel
        self.life -= 2

    def draw(self, surf):
        if self.life > 0:
            pygame.draw.circle(
                surf,
                self.color,
                (int(self.pos.x), int(self.pos.y)),
                4
            )


class PygameWidget(QWidget):
    def __init__(self):
        super().__init__()

        pygame.init()
        pygame.display.init()

        self.w, self.h = 900, 600
        self.surface = pygame.Surface((self.w, self.h))

        self.particles = []
        self.spawn_rate = 5
        self.gravity = 0.1

        self.setSizePolicy(
            QSizePolicy.Policy.Expanding,
            QSizePolicy.Policy.Expanding
        )

        self.timer = QTimer()
        self.timer.timeout.connect(self.game_loop)
        self.timer.start(16)  # ~60 FPS

    def spawn_particles(self):
        for _ in range(self.spawn_rate):
            pos = (self.w // 2, self.h // 2)
            vel = (random.uniform(-2, 2), random.uniform(-2, 2))
            color = (255, random.randint(100, 255), 0)
            self.particles.append(Particle(pos, vel, color))

    def game_loop(self):
        self.surface.fill((20, 20, 20))

        self.spawn_particles()

        alive = []
        for p in self.particles:
            p.update(self.gravity)
            p.draw(self.surface)
            if p.life > 0:
                alive.append(p)

        self.particles = alive

        self.update()

    def paintEvent(self, event):
        data = pygame.image.tobytes(self.surface, "RGB")
        img = QImage(
            data,
            self.w,
            self.h,
            self.w * 3,
            QImage.Format.Format_RGB888
        )

        painter = QPainter(self)
        painter.drawImage(0, 0, img)
        painter.end()

    def resizeEvent(self, event):
        self.w = self.width()
        self.h = self.height()
        self.surface = pygame.Surface((self.w, self.h))

class MainWindow(QWidget):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("PyQt6 + pygame Particle System")

        main_layout = QVBoxLayout()

        # widget-ul pygame – ocupă tot spațiul
        self.pg_widget = PygameWidget()
        main_layout.addWidget(self.pg_widget, stretch=1)

        # panou de controale jos
        control_panel = QVBoxLayout()

        # ----- slider spawn rate -----
        spawn_layout = QHBoxLayout()
        spawn_label = QLabel("Spawn:")
        self.spawn_value = QLabel("5")

        spawn_slider = QSlider(Qt.Orientation.Horizontal)
        spawn_slider.setRange(1, 50)
        spawn_slider.setValue(5)
        spawn_slider.valueChanged.connect(self.update_spawn_rate)

        spawn_layout.addWidget(spawn_label)
        spawn_layout.addWidget(spawn_slider)
        spawn_layout.addWidget(self.spawn_value)

        # ----- slider gravity -----
        gravity_layout = QHBoxLayout()
        gravity_label = QLabel("Gravity:")
        self.gravity_value = QLabel("0.10")

        gravity_slider = QSlider(Qt.Orientation.Horizontal)
        gravity_slider.setRange(0, 50)
        gravity_slider.setValue(10)
        gravity_slider.valueChanged.connect(self.update_gravity)

        gravity_layout.addWidget(gravity_label)
        gravity_layout.addWidget(gravity_slider)
        gravity_layout.addWidget(self.gravity_value)

        control_panel.addLayout(spawn_layout)
        control_panel.addLayout(gravity_layout)

        main_layout.addLayout(control_panel)

        self.setLayout(main_layout)

    def update_spawn_rate(self, v):
        self.pg_widget.spawn_rate = v
        self.spawn_value.setText(str(v))

    def update_gravity(self, v):
        g = v / 100.0
        self.pg_widget.gravity = g
        self.gravity_value.setText(f"{g:.2f}")

if __name__ == "__main__":
    app = QApplication(sys.argv)
    w = MainWindow()
    w.resize(1000, 800)
    w.show()
    sys.exit(app.exec())

Thursday, April 9, 2026

Python 3.14.3 : Simple project with django version 6.0.4 on Fedora 44 beta 12.

Today I used Fedora 44 beta 12 server on VirtualBox, and I wanted to test how Python works with Django on this Linux distribution. In the Fedora distribution, I have Python version 3.14.3 and Django version 6.0.4. I created a basic project with multiple pages, CSS, JavaScript, and an admin interface. It seems that Django is functional, and the result is very good for a basic project.:

Wednesday, April 8, 2026

Python Qt6 : build a mini tool for memory game with PyQt6 !

Today, I tested this python script with PyQt6 to create this matrix data for memory game by click on canvas.
I add few lines of source code and I create the memory game window to test that matrix:

Sunday, March 29, 2026

News : Released v3.9.0 for NiceGUI.

The nicegui python package was released few days ago on the GitHub project, you can install with the pip tool:
python -m pip install nicegui
WARNING: Ignoring invalid distribution ~adquery-ocp (C:\Python313_64bit\Lib\site-packages)
Collecting nicegui
  Downloading nicegui-3.9.0-py3-none-any.whl.metadata (11 kB)
...
Successfully installed aiofiles-25.1.0 httptools-0.7.1 ifaddr-0.2.0 lxml-html-clean-0.4.4 markdown2-2.5.5 nicegui-3.9.0
You can find some examples on the official webpage.

Monday, March 23, 2026

News : Release 0.8.0 of mt940 library.

The mt940 is a library to parse MT940 files. MT940 is a specific SWIFT message type used by the SWIFT network to send and receive end-of-day bank account statements.
The install is easy with the pip tool:
pip install mt940==0.8.0
See the type file MT940 and the .
See the released on the official webpage.

Sunday, March 22, 2026

Python Qt6 : Folder encrypt and decrypt tool with PBKDF2 SALT derived key.

This script securely encrypts both the contents and the name of a folder using a password‑derived Fernet key (AES‑128 + HMAC), where PBKDF2 with a fixed SALT key.
A SALT is used in password‑based key derivation. If your system had no SALT, and someone used a weak password, an attacker could instantly look up the key in a rainbow table.
With a SALT the attacker would need a separate rainbow table for every possible SALT, which is infeasible.
SALT does NOT protect against brute‑force, because PBKDF2 treats the SALT as an input parameter, not as part of the password’s entropy.

Thursday, March 12, 2026

Python Qt6 : schemdraw - 001.

Today, simple example with PyQt6 and schemdraw :
# -*- coding: utf-8 -*-
import sys
import schemdraw
import schemdraw.elements as elm
from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QVBoxLayout, QScrollArea
from PyQt6.QtGui import QPixmap
def draw_bistabil_grid(state):
    """
    state = 0 -> switch spre R3, LED1 aprins
    state = 1 -> switch spre R4, LED2 aprins
    """
    with schemdraw.Drawing(file='bistabil_grid.png', show=False) as d:
        d.config(unit=2.0)

        # Y COORDINATES
        y_led = 0.0
        y_r1  = -2.0
        y_rfb = -4.0
        y_swT = -7.0
        y_gnd = -10.0

        # X COORDINATES
        x_left   = -6.0
        x_right  = 6.0
        x_t1     = -3.0
        x_t2     = 3.0
        x_sw     = 0.0

        # COLORS
        col_T1 = 'green'
        col_T2 = 'orange'

        # LED-uri colorate în funcție de state
        led1_color = 'red' if state == 0 else 'gray'
        led2_color = 'red' if state == 1 else 'gray'

        # 1. LED1 and LED2
        led1 = d.add(elm.LED().down().at((x_left, y_led)).color(led1_color).label('LED1'))
        led2 = d.add(elm.LED().down().at((x_right, y_led)).color(led2_color).label('LED2'))

        # 2. R1 and R2
        r1 = d.add(elm.Resistor().down().at(led1.end).label('R1'))
        r2 = d.add(elm.Resistor().down().at(led2.end).label('R2'))

        n_r1 = d.add(elm.Dot().at(r1.end))
        n_r2 = d.add(elm.Dot().at(r2.end))

        # 3. R3 and R4 (feedback)
        d.add(elm.Line().at(n_r1.center).to((x_t1, y_rfb)))
        r3 = d.add(elm.Resistor().right().at((x_t1, y_rfb)).label('R3'))
        n_r3 = d.add(elm.Dot().at(r3.end))

        d.add(elm.Line().at(n_r2.center).to((x_t2, y_rfb)))
        r4 = d.add(elm.Resistor().left().at((x_t2, y_rfb)).label('R4'))
        n_r4 = d.add(elm.Dot().at(r4.end))

        # 4. Transistors
        t1 = d.add(
            elm.BjtNpn()
            .left()
            .flip()
            .at((x_t1, y_swT))
            .anchor('base')
            .label('T1')
        )

        t2 = d.add(
            elm.BjtNpn()
            .right()
            .at((x_t2, y_swT))
            .anchor('base')
            .label('T2')
        )

        # BASE CONNECTIONS
        d.add(elm.Line().at(n_r4.center).to(t1.base).color(col_T1))
        d.add(elm.Line().at(n_r3.center).to(t2.base).color(col_T2))

        # COLLECTOR CONNECTIONS
        d.add(elm.Line().at(t1.collector).to(n_r1.center).color(col_T1))
        d.add(elm.Line().at(t2.collector).to(n_r2.center).color(col_T2))

        # -------------------------------
        # 5. SWITCH SPDT DESENAT MANUAL
        # -------------------------------

        # Punctele a, b, c
        a = d.add(elm.Dot().at((x_sw - 1, y_swT)))
        b = d.add(elm.Dot().at((x_sw,     y_swT)))
        c = d.add(elm.Dot().at((x_sw + 1, y_swT)))

        # Linii FIXE către R3 și R4
        d.add(elm.Line().at(n_r3.center).to(a.center))
        d.add(elm.Line().at(n_r4.center).to(c.center))

        # Linia FIXĂ către GND
        d.add(elm.Line().at(b.center).to((b.center[0], y_gnd)))

        # Brațul mobil (UNICA linie care se mișcă)
        if state == 0:
            d.add(elm.Line().at(b.center).to(a.center))
        else:
            d.add(elm.Line().at(b.center).to(c.center))

        # 6. Ground bus
        d.add(
            elm.Line()
            .at((x_left - 2, y_gnd))
            .to((x_right + 2, y_gnd))
            .label('0V', loc='bottom')
        )
        d.add(elm.Ground().at((x_left - 2, y_gnd)))

        # EMITTERS TO GND
        d.add(elm.Line().at(t1.emitter).to((t1.emitter[0], y_gnd)).color(col_T1))
        d.add(elm.Line().at(t2.emitter).to((t2.emitter[0], y_gnd)).color(col_T2))


class BistabilGUI(QWidget):
    def __init__(self):
        super().__init__()

        self.state = 0

        self.setWindowTitle("Bistabil Animat – Schema completă")

        # Scroll area
        self.scroll = QScrollArea()
        self.label = QLabel()
        self.scroll.setWidget(self.label)
        self.scroll.setWidgetResizable(True)

        self.button = QPushButton("Comută switch-ul")
        self.button.clicked.connect(self.toggle_switch)

        layout = QVBoxLayout()
        layout.addWidget(self.scroll)
        layout.addWidget(self.button)
        self.setLayout(layout)

        self.update_image()

    def toggle_switch(self):
        self.state = 1 - self.state
        self.update_image()

    def update_image(self):
        draw_bistabil_grid(self.state)
        pix = QPixmap("bistabil_grid.png")
        self.label.setPixmap(pix)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    gui = BistabilGUI()
    gui.show()
    sys.exit(app.exec())

News : Major new features of the 3.15 series, compared to 3.14

Python 3.15 is still in development. This release, 3.15.0a7, is the seventh of eight planned alpha releases.
...The JIT compiler has been significantly upgraded, with 3-4% geometric mean performance improvement on x86-64 Linux over the standard interpreter, and 7-8% speedup on AArch64 macOS over the tail-calling interpreter

Wednesday, March 11, 2026

Saturday, March 7, 2026

Python 3.13.0 : schemdraw high-quality electrical circuit schematic.

Schemdraw is a Python package for producing high-quality electrical circuit schematic diagrams. Circuit elements are added, one at a time, similar to how you might draw them by hand, using Python methods.
This is the install step with pip tool:
pip install schemdraw
WARNING: Ignoring invalid distribution ~adquery-ocp (C:\Python313_64bit\Lib\site-packages)
Collecting schemdraw
  Downloading schemdraw-0.22-py3-none-any.whl.metadata (2.2 kB)
Downloading schemdraw-0.22-py3-none-any.whl (148 kB)
WARNING: Ignoring invalid distribution ~adquery-ocp (C:\Python313_64bit\Lib\site-packages)
Installing collected packages: schemdraw
WARNING: Ignoring invalid distribution ~adquery-ocp (C:\Python313_64bit\Lib\site-packages)
Successfully installed schemdraw-0.22

Tuesday, March 3, 2026

Python 3.13.0 : webcam Falticeni - processing HLS .m3u8 video stream.

Python can process data from an HLS (.m3u8) video stream, such as the one used on the Fălticeni webcam page (which loads the stream through index.m3u8).

Monday, March 2, 2026

Python 3.13.0 : the manim python module - part 002.

The last tutorial was on this post.
The manim packege can be install with pip tool:
pip install manim
...
Successfully installed audioop-lts-0.2.2 av-16.1.0 cloup-3.0.8 glcontext-3.0.0 isosurfaces-0.1.2 manim-0.20.1 manimpango-0.6.1 mapbox-earcut-2.0.0 moderngl-5.12.0 moderngl-window-3.1.1 pycairo-1.29.0 pydub-0.25.1 pyglet-2.1.13 pyglm-2.8.3 screeninfo-0.8.1 skia-pathops-0.9.2 srt-3.5.3
The last tutorial was on this post.