@@ -173,8 +173,11 @@ def get_proteingym_dataset(
173173 incomplete_naturalness_df ["seq_id" ] = incomplete_naturalness_df ["seq_id" ].apply (
174174 lambda x : maybe_modify_seq_id (dms_id , x )
175175 )
176- if any (incomplete_naturalness_df ["wt_marginal" ] <= 0 ):
177- raise ValueError ("wt_marginal is negative or zero" )
176+ if any (incomplete_naturalness_df ["wt_marginal" ] < 0 ):
177+ raise ValueError (f"wt_marginal for { dms_id } is negative, eg: { incomplete_naturalness_df [incomplete_naturalness_df ['wt_marginal' ] <= 0 ]['wt_marginal' ].tolist ()[:5 ]} " )
178+
179+ def safe_log_for_wt_naturalness (x ):
180+ return np .log (max (x , 1e-20 ))
178181 if (
179182 "model" in incomplete_naturalness_df .columns
180183 and incomplete_naturalness_df .model .unique ().size > 1
@@ -184,8 +187,8 @@ def get_proteingym_dataset(
184187 # Note that we deliberately lose the wt_marginal column - we want this to crash
185188 # later on, unless the user specifies the proper column names.
186189 incomplete_naturalness_df ["log_wt_marginal" ] = incomplete_naturalness_df [
187- "wt_marginal"
188- ].apply (np . log )
190+ "wt_marginal"
191+ ].apply (safe_log_for_wt_naturalness )
189192 incomplete_naturalness_df ["model" ] = incomplete_naturalness_df ["model" ].apply (
190193 lambda x : f"log_wt_marginal_{ x } "
191194 )
@@ -195,7 +198,7 @@ def get_proteingym_dataset(
195198 else :
196199 # Otherwise, under normal circumstances, just set up seq_id as index.
197200 incomplete_naturalness_df = incomplete_naturalness_df .set_index ("seq_id" , drop = False )
198- incomplete_naturalness_df ['log_wt_marginal' ] = incomplete_naturalness_df ['wt_marginal' ].apply (np . log )
201+ incomplete_naturalness_df ['log_wt_marginal' ] = incomplete_naturalness_df ['wt_marginal' ].apply (safe_log_for_wt_naturalness )
199202 incomplete_naturalness_df .drop (columns = ['wt_marginal' ], inplace = True )
200203
201204 seq_ids_with_naturalness = set (incomplete_naturalness_df .index )
0 commit comments