Coverage for backend/django/core/auxiliary/methods/custom_property_packages/add_compound_to_package.py: 60%
13 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-03-26 20:57 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-03-26 20:57 +0000
1from ...models.CustomPropertyPackage import CustomPropertyPackage, CustomPropertyPackageProperty, CustomPropertyPackagePropertyEnum, Kappa, CustomCompound
3def add_compound_to_property_package(package: CustomPropertyPackage, compound: CustomCompound):
4 """
5 We need to make sure every pair benzene-toluene, toluene-benzene, benzene-benzene, toluene-toluene has a kappa entry.
6 We assume that all existing ones are set up correctly, and just add the missing ones.
7 """
10 # add the kappas
11 kappas :list[Kappa] = []
12 for compound2 in package.compounds.all(): 12 ↛ 13line 12 didn't jump to line 13 because the loop on line 12 never started
13 kappas.append(Kappa(
14 flowsheet=package.flowsheet,
15 package=package,
16 compound1=compound,
17 compound2=compound2,
18 ))
19 # and add the inverse
20 kappas.append(Kappa(
21 flowsheet=package.flowsheet,
22 package=package,
23 compound1=compound2,
24 compound2=compound,
25 ))
27 # and add the self interaction kappa
28 kappas.append(Kappa(
29 flowsheet=package.flowsheet,
30 package=package,
31 compound1=compound,
32 compound2=compound,
33 ))
35 package.compounds.add(compound)
37 Kappa.objects.bulk_create(kappas)
39def remove_compound_from_property_package(package: CustomPropertyPackage, compound: CustomCompound):
40 """
41 We need to remove all the kappas that involve this compound.
42 Note that this does not remove the compound from the flowsheet, it can be used elsewhere.
43 """
45 Kappa.objects.filter(
46 package=package,
47 compound1=compound
48 ).delete()
50 Kappa.objects.filter(
51 package=package,
52 compound2=compound
53 ).delete()
55 package.compounds.remove(compound)