File size: 1,499 Bytes
6d3b444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44

import numpy as np
import random

def evaluate_stability(seq):
    hydrophobic_aas = set("AILMFWYV")
    hydrophobic_ratio = sum(1 for aa in seq if aa in hydrophobic_aas) / len(seq)
    aromaticity_score = seq.count('F') + seq.count('W') + seq.count('Y')
    return round((hydrophobic_ratio * 0.6 + aromaticity_score * 0.1), 4)

def evaluate_affinity(seq):
    entropy = len(set(seq)) / len(seq)
    return round((1 - entropy) * 0.8 + random.uniform(0.1, 0.3), 4)

def run_simulations(binder_candidates, engines=['SimLite']):
    scored_binders = []
    rejections = []

    for binder in binder_candidates.get("generated_binders", []):
        sequence = binder["sequence"]
        stability = evaluate_stability(sequence)
        affinity = evaluate_affinity(sequence)
        reasons = []

        if stability < 0.3:
            reasons.append("Low stability score")
        if affinity < 0.3:
            reasons.append("Low predicted affinity")

        if reasons:
            binder["rejection_reason"] = reasons
            rejections.append(binder)
        else:
            binder["stability_score"] = stability
            binder["predicted_affinity"] = affinity
            binder["structure_engine"] = engines[0]
            binder["simulation_trace"] = f"Hydrophobic: {round(stability, 3)}, Entropy-Based Affinity: {round(affinity, 3)}"
            scored_binders.append(binder)

    return {
        "validated_binders": scored_binders,
        "rejected_binders": rejections
    }