@@ -86,57 +86,20 @@ class HasSynthesisInfo(BaseModel):
86
86
synthesis_constituents : list [Constituent ] = Field ([])
87
87
"""A list of references to constituent materials giving the amount and relevant inlined details of consituent items."""
88
88
89
+ synthesis_products : list [Constituent ] = Field ([])
90
+ """A list of references to constituent materials giving the amount and relevant inlined details of relevant sythesis products."""
91
+
89
92
synthesis_description : str | None = None
90
93
"""Free-text details of the procedure applied to synthesise the sample"""
91
94
92
95
@root_validator
93
- def add_missing_synthesis_relationships (cls , values ):
94
- """Add any missing sample synthesis constituents to parent relationships"""
95
- from pydatalab .models .relationships import RelationshipType , TypedRelationship
96
-
97
- constituents_set = set ()
98
- if values .get ("synthesis_constituents" ) is not None :
99
- existing_parent_relationship_ids = set ()
100
- if values .get ("relationships" ) is not None :
101
- existing_parent_relationship_ids = {
102
- relationship .refcode or relationship .item_id
103
- for relationship in values ["relationships" ]
104
- if relationship .relation == RelationshipType .PARENT
105
- }
106
- else :
107
- values ["relationships" ] = []
108
-
109
- for constituent in values .get ("synthesis_constituents" , []):
110
- # If this is an inline relationship, just skip it
111
- if isinstance (constituent .item , InlineSubstance ):
112
- continue
113
-
114
- constituent_id = constituent .item .refcode or constituent .item .item_id
115
-
116
- if constituent_id not in existing_parent_relationship_ids :
117
- relationship = TypedRelationship (
118
- relation = RelationshipType .PARENT ,
119
- refcode = constituent .item .refcode ,
120
- item_id = constituent .item .item_id ,
121
- type = constituent .item .type ,
122
- description = "Is a constituent of" ,
123
- )
124
- values ["relationships" ].append (relationship )
125
-
126
- # Accumulate all constituent IDs in a set to filter those that have been deleted
127
- constituents_set .add (constituent_id )
128
-
129
- # Finally, filter out any parent relationships with item that were removed
130
- # from the synthesis constituents
131
- values ["relationships" ] = [
132
- rel
133
- for rel in values ["relationships" ]
134
- if not (
135
- (rel .refcode or rel .item_id ) not in constituents_set
136
- and rel .relation == RelationshipType .PARENT
137
- and rel .type in ("samples" , "starting_materials" )
96
+ def add_self_product (cls , values ):
97
+ if not values .get ("synthesis_products" ):
98
+ values ["synthesis_products" ].append (
99
+ Constituent (
100
+ quantity = None , item = {"type" : values ["type" ], "refcode" : values ["refcode" ]}
101
+ )
138
102
)
139
- ]
140
103
141
104
return values
142
105
0 commit comments