0%

硼烷的styx参数计算简易程序

根据规则计算出硼烷的styx参数,未包含C,你可以使用加电子来模拟。

三个参数分别是硼的个数,氢的个数,负电荷的个数。

具体请见http://47.122.18.217:8502/

(注意,本程序未经过大量验证!请手动验证!)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import numpy as np
from scipy.optimize import nnls

def calculate_styx(B, H, e):
n=B
m=H-n

# Applying the provided rules
if n< 3:
# For n_B < 3, t = 0 and y = 0 (no BBB or BB bonds)
t = 0
s = n - e / 2
x = m - n + e / 2
y = n - m / 2
else:
# Matrix for the coefficients
M = np.array([
[1, 0, 0, 1], # s + x = m 氢原子守恒
[1, 2, 2, 1], # s + 2t + 2y + x = 2n + n_e 电子守恒
[4, 6, 4, 2] # 4s + 6t + 4y + 2x = 6n 轨道守恒(8电子规则)
])

# Vector for the constants
Bond = np.array([m, 2 * n + e, 6 * n])

# Solve using non-negative least squares
solution, _ = nnls(M, Bond)

# Extracting the parameters and rounding them to nearest integers
s, t, y, x = np.round(solution).astype(int)

# Check if all parameters are non-negative integers
if all(param >= 0 for param in [s, t, y, x]):
return {"s": s, "t": t, "y": y, "x": x}

return "No valid STYX parameters found."

# Example calculation for a general BH compound with corrected m value
calculate_styx(4, 4, 2)