def get_bo(ac, p_ua, du, valences):
bo = ac.copy()
ua = list(p_ua)
while len(du) > 1:
ua_pairs = itertools.combinations(ua, 2)
for i, j in ua_pairs:
if bo[i, j] > 0:
bo[i, j] += 1
bo[j, i] += 1
break
bo_valence = list(bo.sum(axis=1))
ua_new, du_new = get_ua(valences, bo_valence)
if du_new != du:
ua = [ua_i for ua_i in p_ua if ua_i in ua_new]
du = copy.copy(du_new)
else:
break
return bo
.
.
# implemenation of algorithm shown in Figure 2
# UA: unsaturated atoms
# DU: degree of unsaturation (u matrix in Figure)
# best_BO: Bcurr in Figure
is_best_bo = False
for valences in valences_list:
ac_valence = list(ac.sum(axis=1))
ua, du_from_ac = get_ua(valences, ac_valence)
if len(ua) == 0 or bo_is_ok(ac, ac, charg, du_from_ac,
atomic_valence_electrons,
atomic_num_list,
charged_fragments):
best_bo = ac.copy()
break
ua_perm = itertools.permutations(ua)
for a in ua_perm:
bo = get_bo(ac, a, du_from_ac, valences)
if bo_is_ok(bo, ac, charg, du_from_ac,
atomic_valence_electrons,
atomic_num_list,
charged_fragments):
best_bo = bo.copy()
is_best_bo = True
break
elif bo.sum() > best_bo.sum():
best_bo = bo.copy()
print('best comb not found')
if is_best_bo:
break
.
.
.
the changed lines: