polymer-aging-ml / pages /Collaborative_Research.py
devjas1
Adds collaborative research interface for POLYMEROS
6b58aaa
raw
history blame
25.8 kB
"""
Collaborative Research Interface for POLYMEROS
Community-driven research and validation tools
"""
import streamlit as st
import json
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
from typing import Dict, List, Any
import uuid
# Import POLYMEROS components
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from modules.enhanced_data import KnowledgeGraph, ContextualSpectrum
def init_collaborative_session():
"""Initialize collaborative research session"""
if "research_projects" not in st.session_state:
st.session_state.research_projects = load_demo_projects()
if "community_hypotheses" not in st.session_state:
st.session_state.community_hypotheses = load_demo_hypotheses()
if "user_profile" not in st.session_state:
st.session_state.user_profile = {
"user_id": "demo_researcher",
"name": "Demo Researcher",
"expertise_areas": ["polymer_chemistry", "spectroscopy"],
"reputation_score": 85,
"contributions": 12,
}
def load_demo_projects():
"""Load demonstration research projects"""
return [
{
"id": "proj_001",
"title": "Microplastic Degradation Pathways",
"description": "Investigating spectroscopic signatures of microplastic degradation in marine environments",
"lead_researcher": "Dr. Sarah Chen",
"institution": "Ocean Research Institute",
"collaborators": ["University of Tokyo", "MIT Marine Lab"],
"status": "active",
"created_date": "2024-01-15",
"datasets": 3,
"participants": 8,
"recent_activity": "New FTIR dataset uploaded",
"tags": ["microplastics", "marine_degradation", "FTIR"],
},
{
"id": "proj_002",
"title": "Biodegradable Polymer Performance",
"description": "Comparative study of biodegradable polymer aging under different environmental conditions",
"lead_researcher": "Prof. Michael Rodriguez",
"institution": "Sustainable Materials Lab",
"collaborators": ["Stanford University", "Green Chemistry Institute"],
"status": "recruiting",
"created_date": "2024-02-20",
"datasets": 1,
"participants": 3,
"recent_activity": "Seeking Raman spectroscopy expertise",
"tags": ["biodegradable", "sustainability", "aging"],
},
{
"id": "proj_003",
"title": "AI-Assisted Polymer Discovery",
"description": "Developing machine learning models for predicting polymer properties from spectroscopic data",
"lead_researcher": "Dr. Aisha Patel",
"institution": "AI Materials Research Center",
"collaborators": ["DeepMind", "Google Research"],
"status": "published",
"created_date": "2023-11-10",
"datasets": 15,
"participants": 25,
"recent_activity": "Results published in Nature Materials",
"tags": ["machine_learning", "property_prediction", "discovery"],
},
]
def load_demo_hypotheses():
"""Load demonstration community hypotheses"""
return [
{
"id": "hyp_001",
"statement": "Carbonyl peak intensity at 1715 cm⁻¹ correlates linearly with UV exposure time in PE samples",
"proposer": "Dr. Sarah Chen",
"institution": "Ocean Research Institute",
"created_date": "2024-03-01",
"supporting_evidence": [
"Time-series FTIR data from 50 PE samples",
"Controlled UV chamber experiments",
"Statistical correlation analysis (R² = 0.89)",
],
"validation_status": "under_review",
"peer_scores": [4.2, 3.8, 4.5, 4.0],
"experimental_confirmations": 2,
"tags": ["PE", "UV_degradation", "carbonyl"],
"discussion_points": 8,
},
{
"id": "hyp_002",
"statement": "Machine learning models show systematic bias against weathered polymers with low crystallinity",
"proposer": "Prof. Michael Rodriguez",
"institution": "Sustainable Materials Lab",
"created_date": "2024-02-15",
"supporting_evidence": [
"Model performance analysis across 1000+ samples",
"Crystallinity correlation studies",
"Bias detection algorithm results",
],
"validation_status": "confirmed",
"peer_scores": [4.8, 4.5, 4.7, 4.9],
"experimental_confirmations": 5,
"tags": ["machine_learning", "bias", "crystallinity"],
"discussion_points": 15,
},
]
def render_research_projects():
"""Render collaborative research projects interface"""
st.header("🔬 Collaborative Research Projects")
# Project filters
col1, col2, col3 = st.columns(3)
with col1:
status_filter = st.selectbox(
"Status:", ["all", "active", "recruiting", "published"]
)
with col2:
tag_filter = st.selectbox(
"Domain:", ["all", "microplastics", "biodegradable", "machine_learning"]
)
with col3:
sort_by = st.selectbox("Sort by:", ["recent", "participants", "datasets"])
# Filter and sort projects
projects = st.session_state.research_projects
if status_filter != "all":
projects = [p for p in projects if p["status"] == status_filter]
if tag_filter != "all":
projects = [p for p in projects if tag_filter in p["tags"]]
# Display projects
for project in projects:
with st.expander(f"📋 {project['title']} ({project['status'].title()})"):
col1, col2 = st.columns([2, 1])
with col1:
st.write(f"**Description:** {project['description']}")
st.write(
f"**Lead Researcher:** {project['lead_researcher']} ({project['institution']})"
)
st.write(f"**Collaborators:** {', '.join(project['collaborators'])}")
st.write(f"**Tags:** {', '.join(project['tags'])}")
with col2:
st.metric("Participants", project["participants"])
st.metric("Datasets", project["datasets"])
st.write(f"**Created:** {project['created_date']}")
st.write(f"**Recent:** {project['recent_activity']}")
# Action buttons
button_col1, button_col2, button_col3 = st.columns(3)
with button_col1:
if st.button(f"Join Project", key=f"join_{project['id']}"):
st.success("Interest registered! Project lead will be notified.")
with button_col2:
if st.button(f"View Details", key=f"view_{project['id']}"):
render_project_details(project)
with button_col3:
if st.button(f"Contact Lead", key=f"contact_{project['id']}"):
st.info("Contact request sent to project lead.")
# Create new project
st.subheader("➕ Start New Project")
with st.expander("Create Research Project"):
project_title = st.text_input("Project Title:")
project_description = st.text_area("Project Description:")
research_areas = st.multiselect(
"Research Areas:",
[
"polymer_chemistry",
"spectroscopy",
"machine_learning",
"sustainability",
"degradation",
],
)
if st.button("Create Project"):
if project_title and project_description:
new_project = {
"id": f"proj_{len(st.session_state.research_projects) + 1:03d}",
"title": project_title,
"description": project_description,
"lead_researcher": st.session_state.user_profile["name"],
"institution": "User Institution",
"collaborators": [],
"status": "recruiting",
"created_date": datetime.now().strftime("%Y-%m-%d"),
"datasets": 0,
"participants": 1,
"recent_activity": "Project created",
"tags": research_areas,
}
st.session_state.research_projects.append(new_project)
st.success("Project created successfully!")
else:
st.error("Please fill in required fields.")
def render_project_details(project):
"""Render detailed project view"""
st.subheader(f"Project Details: {project['title']}")
# Project overview
col1, col2 = st.columns(2)
with col1:
st.write(f"**Status:** {project['status'].title()}")
st.write(f"**Lead:** {project['lead_researcher']}")
st.write(f"**Institution:** {project['institution']}")
with col2:
st.write(f"**Created:** {project['created_date']}")
st.write(f"**Participants:** {project['participants']}")
st.write(f"**Datasets:** {project['datasets']}")
# Tabs for different project aspects
tab1, tab2, tab3, tab4 = st.tabs(
["Overview", "Datasets", "Collaborators", "Timeline"]
)
with tab1:
st.write(project["description"])
st.write(f"**Research Areas:** {', '.join(project['tags'])}")
with tab2:
st.write("**Available Datasets:**")
# Mock dataset information
datasets = [
{
"name": "PE_UV_exposure_series",
"type": "FTIR",
"samples": 150,
"uploaded": "2024-03-01",
},
{
"name": "Weathered_samples_marine",
"type": "Raman",
"samples": 75,
"uploaded": "2024-02-15",
},
{
"name": "Control_samples_lab",
"type": "FTIR",
"samples": 50,
"uploaded": "2024-01-20",
},
]
for dataset in datasets:
with st.expander(f"📊 {dataset['name']}"):
st.write(f"**Type:** {dataset['type']}")
st.write(f"**Samples:** {dataset['samples']}")
st.write(f"**Uploaded:** {dataset['uploaded']}")
if st.button(f"Access Dataset", key=f"access_{dataset['name']}"):
st.info("Dataset access request submitted.")
with tab3:
st.write("**Project Collaborators:**")
for collab in project["collaborators"]:
st.write(f"• {collab}")
st.write("**Recent Contributors:**")
contributors = [
{
"name": "Dr. Sarah Chen",
"contribution": "FTIR dataset",
"date": "2024-03-01",
},
{
"name": "Alex Johnson",
"contribution": "Data analysis scripts",
"date": "2024-02-28",
},
{
"name": "Prof. Lisa Wang",
"contribution": "Methodology review",
"date": "2024-02-25",
},
]
for contrib in contributors:
st.write(
f"• **{contrib['name']}:** {contrib['contribution']} ({contrib['date']})"
)
with tab4:
st.write("**Project Timeline:**")
timeline_events = [
{
"date": "2024-03-01",
"event": "New FTIR dataset uploaded",
"type": "data",
},
{
"date": "2024-02-25",
"event": "Methodology peer review completed",
"type": "review",
},
{
"date": "2024-02-15",
"event": "Two new collaborators joined",
"type": "team",
},
{
"date": "2024-01-20",
"event": "Initial dataset published",
"type": "data",
},
{"date": "2024-01-15", "event": "Project initiated", "type": "milestone"},
]
for event in timeline_events:
event_icon = {"data": "📊", "review": "🔍", "team": "👥", "milestone": "🎯"}
st.write(
f"{event_icon.get(event['type'], '📅')} **{event['date']}:** {event['event']}"
)
def render_community_hypotheses():
"""Render community hypothesis validation interface"""
st.header("🧪 Community Hypotheses")
# Hypothesis filters
col1, col2 = st.columns(2)
with col1:
status_filter = st.selectbox(
"Validation Status:", ["all", "under_review", "confirmed", "rejected"]
)
with col2:
st.selectbox(
"Research Domain:",
["all", "degradation", "machine_learning", "characterization"],
)
# Display hypotheses
hypotheses = st.session_state.community_hypotheses
for hypothesis in hypotheses:
# Calculate average peer score
avg_score = np.mean(hypothesis["peer_scores"])
with st.expander(
f"🧬 {hypothesis['statement'][:80]}... (Score: {avg_score:.1f}/5)"
):
col1, col2 = st.columns([2, 1])
with col1:
st.write(f"**Full Statement:** {hypothesis['statement']}")
st.write(
f"**Proposer:** {hypothesis['proposer']} ({hypothesis['institution']})"
)
st.write(f"**Status:** {hypothesis['validation_status'].title()}")
st.write("**Supporting Evidence:**")
for evidence in hypothesis["supporting_evidence"]:
st.write(f"• {evidence}")
with col2:
st.metric("Peer Score", f"{avg_score:.1f}/5")
st.metric("Confirmations", hypothesis["experimental_confirmations"])
st.metric("Discussions", hypothesis["discussion_points"])
st.write(f"**Proposed:** {hypothesis['created_date']}")
# Peer review section
st.subheader("Peer Review")
review_col1, review_col2 = st.columns(2)
with review_col1:
user_score = st.slider(
"Your Score:", 1, 5, 3, key=f"score_{hypothesis['id']}"
)
with review_col2:
if st.button("Submit Review", key=f"review_{hypothesis['id']}"):
hypothesis["peer_scores"].append(user_score)
st.success("Review submitted!")
# Comments and discussion
st.subheader("Community Discussion")
# Mock discussion
discussions = [
{
"author": "Dr. Sarah Chen",
"comment": "Interesting correlation! Would like to see this tested with PP samples.",
"date": "2024-03-02",
},
{
"author": "Prof. Wang",
"comment": "The R² value is impressive. Have you controlled for temperature effects?",
"date": "2024-03-01",
},
{
"author": "Alex Johnson",
"comment": "We're seeing similar patterns in our lab. Happy to collaborate on validation.",
"date": "2024-02-28",
},
]
for discussion in discussions:
st.write(
f"**{discussion['author']}** ({discussion['date']}): {discussion['comment']}"
)
# Add comment
new_comment = st.text_area(
"Add your comment:", key=f"comment_{hypothesis['id']}"
)
if st.button("Post Comment", key=f"post_{hypothesis['id']}"):
if new_comment:
st.success("Comment posted!")
else:
st.error("Please enter a comment.")
# Submit new hypothesis
st.subheader("➕ Propose New Hypothesis")
with st.expander("Submit Hypothesis"):
hyp_statement = st.text_area("Hypothesis Statement:")
hyp_evidence = st.text_area("Supporting Evidence (one per line):")
hyp_tags = st.multiselect(
"Research Tags:",
[
"degradation",
"machine_learning",
"spectroscopy",
"characterization",
"prediction",
],
)
if st.button("Submit Hypothesis"):
if hyp_statement and hyp_evidence:
evidence_list = [
e.strip() for e in hyp_evidence.split("\n") if e.strip()
]
new_hypothesis = {
"id": f"hyp_{len(st.session_state.community_hypotheses) + 1:03d}",
"statement": hyp_statement,
"proposer": st.session_state.user_profile["name"],
"institution": "User Institution",
"created_date": datetime.now().strftime("%Y-%m-%d"),
"supporting_evidence": evidence_list,
"validation_status": "under_review",
"peer_scores": [],
"experimental_confirmations": 0,
"tags": hyp_tags,
"discussion_points": 0,
}
st.session_state.community_hypotheses.append(new_hypothesis)
st.success("Hypothesis submitted for peer review!")
else:
st.error("Please provide hypothesis statement and evidence.")
def render_peer_review_system():
"""Render peer review and reputation system"""
st.header("👥 Peer Review System")
user_profile = st.session_state.user_profile
# User reputation dashboard
st.subheader("Your Research Profile")
col1, col2, col3, col4 = st.columns(4)
with col1:
st.metric("Reputation Score", user_profile["reputation_score"])
with col2:
st.metric("Contributions", user_profile["contributions"])
with col3:
st.metric("Expertise Areas", len(user_profile["expertise_areas"]))
with col4:
st.metric("Active Reviews", 3) # Mock data
# Expertise areas
st.subheader("Research Expertise")
current_expertise = user_profile["expertise_areas"]
all_expertise = [
"polymer_chemistry",
"spectroscopy",
"machine_learning",
"materials_science",
"degradation_mechanisms",
"sustainability",
]
new_expertise = st.multiselect(
"Update your expertise areas:", all_expertise, default=current_expertise
)
if new_expertise != current_expertise:
user_profile["expertise_areas"] = new_expertise
st.success("Expertise areas updated!")
# Pending reviews
st.subheader("Pending Reviews")
pending_reviews = [
{
"type": "hypothesis",
"title": "Spectral band shifts indicate polymer chain scission",
"author": "Dr. James Smith",
"deadline": "2024-03-10",
"complexity": "medium",
},
{
"type": "dataset",
"title": "UV-degraded PP sample collection",
"author": "Prof. Lisa Wang",
"deadline": "2024-03-15",
"complexity": "low",
},
]
for review in pending_reviews:
with st.expander(f"📋 {review['title']} (Due: {review['deadline']})"):
st.write(f"**Type:** {review['type'].title()}")
st.write(f"**Author:** {review['author']}")
st.write(f"**Complexity:** {review['complexity'].title()}")
st.write(f"**Deadline:** {review['deadline']}")
if st.button("Start Review", key=f"start_{review['title'][:20]}"):
st.info("Review interface would open here.")
# Review quality metrics
st.subheader("Review Quality Metrics")
metrics = {
"Average Review Time": "2.3 days",
"Review Accuracy": "94%",
"Helpfulness Score": "4.7/5",
"Reviews Completed": "28",
}
metric_cols = st.columns(len(metrics))
for i, (metric, value) in enumerate(metrics.items()):
with metric_cols[i]:
st.metric(metric, value)
def render_knowledge_sharing():
"""Render knowledge sharing and collaboration tools"""
st.header("📚 Knowledge Sharing Hub")
# Recent contributions
st.subheader("Recent Community Contributions")
contributions = [
{
"type": "dataset",
"title": "Marine microplastic spectral library",
"contributor": "Dr. Sarah Chen",
"date": "2024-03-05",
"downloads": 47,
"rating": 4.8,
},
{
"type": "analysis_script",
"title": "Automated peak identification algorithm",
"contributor": "Alex Johnson",
"date": "2024-03-03",
"downloads": 23,
"rating": 4.6,
},
{
"type": "methodology",
"title": "Best practices for sample preparation",
"contributor": "Prof. Michael Rodriguez",
"date": "2024-03-01",
"downloads": 156,
"rating": 4.9,
},
]
for contrib in contributions:
with st.expander(f"📊 {contrib['title']} by {contrib['contributor']}"):
col1, col2 = st.columns([2, 1])
with col1:
st.write(f"**Type:** {contrib['type'].replace('_', ' ').title()}")
st.write(f"**Contributor:** {contrib['contributor']}")
st.write(f"**Date:** {contrib['date']}")
with col2:
st.metric("Downloads", contrib["downloads"])
st.metric("Rating", f"{contrib['rating']}/5")
if st.button("Access Resource", key=f"access_{contrib['title'][:20]}"):
st.success("Resource access granted!")
# Upload new resource
st.subheader("➕ Share Knowledge Resource")
with st.expander("Upload Resource"):
resource_type = st.selectbox(
"Resource Type:", ["dataset", "analysis_script", "methodology"]
)
resource_title = st.text_input("Resource Title:")
resource_description = st.text_area("Description:")
resource_tags = st.multiselect(
"Tags:",
[
"spectroscopy",
"polymer_aging",
"machine_learning",
"data_analysis",
"methodology",
],
)
uploaded_file = st.file_uploader("Upload File:")
if st.button("Share Resource"):
if (
resource_title
and resource_description
and resource_tags
and uploaded_file
):
st.success(
f"Resource of type '{resource_type}' uploaded and shared with the community!"
)
else:
st.error("Please fill in all required fields.")
def main():
"""Main collaborative research interface"""
st.set_page_config(
page_title="POLYMEROS Collaborative Research", page_icon="👥", layout="wide"
)
st.title("👥 POLYMEROS Collaborative Research")
st.markdown("**Community-Driven Research and Validation Platform**")
# Initialize session
init_collaborative_session()
# Sidebar navigation
st.sidebar.title("🤝 Collaboration Tools")
page = st.sidebar.selectbox(
"Select tool:",
[
"Research Projects",
"Community Hypotheses",
"Peer Review System",
"Knowledge Sharing",
],
)
# Display user profile in sidebar
st.sidebar.markdown("---")
st.sidebar.markdown("**Your Profile**")
profile = st.session_state.user_profile
st.sidebar.write(f"**Name:** {profile['name']}")
st.sidebar.write(f"**Reputation:** {profile['reputation_score']}")
st.sidebar.write(f"**Contributions:** {profile['contributions']}")
# Render selected page
if page == "Research Projects":
render_research_projects()
elif page == "Community Hypotheses":
render_community_hypotheses()
elif page == "Peer Review System":
render_peer_review_system()
elif page == "Knowledge Sharing":
render_knowledge_sharing()
# Footer
st.sidebar.markdown("---")
st.sidebar.markdown("**POLYMEROS Community**")
st.sidebar.markdown("*Advancing polymer science together*")
if __name__ == "__main__":
main()