# -*- coding: utf-8 -*-
"""Round 244: batch add 5 Materials Science and Engineering PhD (second-tier U.S. sweep)
- CMU MSE PhD (Fall Jan 8, $75; GRE WAIVED since Fall 2022; TOEFL iBT 84 / IELTS 6.5 / DET 105)
- Cornell MSE PhD (Dec 1 2026 11:59pm EDT; GRE optional; TOEFL R4/W4/L3.5/S4; IELTS 7.0; 10 semesters)
- Northwestern MSE PhD (Dec 1; GRE not required and not reviewed; TOEFL iBT 90 / IELTS 7.0; 12 units; full funding)
- UMich MSE PhD (Dec 15 Fall; GRE no longer required for PhD; TOEFL iBT 84; continuous support)
- UCSD MATS PhD (Jan 6 2027 11:59pm PST; GRE optional; admitted Quant 85-90 percentile; 48 units; Comprehensive+Senate exam)
"""
import os, re

BASE = os.path.dirname(os.path.abspath(__file__))
DET = os.path.join(BASE, "details")
os.makedirs(DET, exist_ok=True)

PROGRAMS = [
    {
        "id": "cmu-mse-phd",
        "s": "cmu",
        "n": "材料科学与工程博士",
        "en": "PhD in Materials Science and Engineering (Carnegie Mellon University, College of Engineering, Department of Materials Science and Engineering; research emphasizes in-depth independent research; MS may be earned en route; related MS tracks include computational materials science, additive manufacturing, energy science and technology and policy)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 4-5 years; research begins intensively in second semester; qualifying procedure; MS may be earned en route; graduate program timetable set to allow graduation in four years; all students have office space separate from laboratory",
        "ddl": "Fall 2027 admission: application opens October 1, 2026. **PhD application deadline January 8, 2027** (MS deadline January 15, 2027). Spring admission PhD June 15 - August 31. Application fee $75 USD (cannot be waived or deferred). Info sessions: PhD Dec 12, Masters Dec 13.",
        "lang": "TOEFL iBT minimum 84 total (Reading 22, Listening 22, Speaking 18, Writing 22); IELTS Academic minimum 6.5; Duolingo DET minimum 105; scores sent electronically to CMU College of Engineering; required for non-native English speakers",
        "test": {"cls": "GRE WAIVED for Fall 2022 cycle and later (CMU MSE: 'Official GRE test scores *WAIVED for Fall 2022 applications'). New department admissions page no longer lists GRE. 3 LOR required for PhD (1 required + 1 optional for MS); essay questions; CV/resume; uploaded unofficial transcripts; minimum 'B' average (3.0/4.0) in materials science or related discipline."},
        "tui": "PhD students are at least partially funded and encouraged to apply for fellowships (CMU Graduate School: 'students in master's programs are self-supporting, and Ph.D. students are at least partially funded'). Research assistantships funded by faculty grants; teaching assistantships available; application fee $75 cannot be waived or deferred.",
        "url": "details/cmu-mse-phd.html",
    },
    {
        "id": "cornell-mse-phd",
        "s": "cornell",
        "n": "材料科学与工程博士",
        "en": "PhD in Materials Science and Engineering (Cornell University, David A. Duffield College of Engineering, Department of Materials Science and Engineering; students from materials science, mechanical, chemical, chemistry, and related engineering backgrounds welcome; MS and MEng are separate degree tracks)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Minimum 10 semesters of graduate study; Qualifying Exam (Q exam) Spring of first year; A Exam (admission to candidacy) Spring of second year; B Exam (dissertation defense) Spring of fifth year; Responsible Conduct of Research training required; ORCID required; Student Progress Reviews begin second year",
        "ddl": "Fall 2027 admission: applications open mid-September 2026. **PhD deadline December 1, 2026, 11:59 pm EDT** (MS deadline February 1, 2027; MEng deadline January 2 at 11:59pm EDT). All required materials including LOR must be uploaded by deadline.",
        "lang": "TOEFL iBT minimum R4 / W4 / L3.5 / S4 (Cornell Graduate School scale; equivalent to iBT ~90+); Cornell does not accept 'My Best' iBT superscore; IELTS Academic minimum overall 7.0; ETS Cornell 2098; department code 0000 undecided",
        "test": {"cls": "GRE OPTIONAL for PhD (Cornell MSE: 'The GRE is optional for our Ph.D. program. You may submit GRE results if you feel that your GRE results help to demonstrate math ability that is otherwise not demonstrated in your academic records.' No minimum score; no penalty for not submitting. 3 LOR through ApplyWeb; SOP; personal statement; unofficial transcripts; bachelor's degree in engineering or physical science."},
        "tui": "PhD students typically receive full funding through research assistantships, teaching assistantships, and fellowships (full tuition waiver + 9-month stipend + health insurance). Cornell Graduate School application fee; fee waivers available for eligible applicants.",
        "url": "details/cornell-mse-phd.html",
    },
    {
        "id": "nu-mse-phd",
        "s": "nu",
        "n": "材料科学与工程博士",
        "en": "PhD in Materials Science and Engineering (Northwestern University, Robert R. McCormick School of Engineering and Applied Science, Department of Materials Science and Engineering; world's first academic department of its kind; interdisciplinary collaboration with Feinberg School of Medicine and Argonne National Lab)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "12 units total (up to 6 units credit for MS); core courses: MAT_SCI 401 Chemical & Statistical Thermodynamics, 402 Structure of Crystalline/Noncrystalline, 404-1 Fundamentals of Soft Matter, 404-2 Imperfections, 405 Physics of Solids, 406 Mechanical Properties, 408 Phase Transformations; 2 departmental electives; 4 free electives; minimum 2 quarters TA (20 hrs/week); preliminary evaluation; qualifying exam; public oral dissertation defense",
        "ddl": "Fall 2027 admission: application portal opens September 10, 2026. **PhD deadline December 1, 2026, 11:59 pm (includes LOR)**. Decisions January 2027; group visits February-March; decision deadline April 15, 2027. (TGS department list shows Dec 3 as secondary reference; department page Dec 1 is authoritative.)",
        "lang": "TOEFL iBT minimum 90 for PhD (TGS minimum; MS minimum 80); IELTS Academic minimum 7.0; ETS Northwestern 1565; scores valid 5 years from test date; waivers available for applicants with undergraduate/graduate degree from English-instructed institution",
        "test": {"cls": "GRE NOT REQUIRED AND NOT REVIEWED (Northwestern MSE: 'The GRE is not required for admission, nor will it be reviewed by the committee if submitted.' PhD applicants evaluated on prior academic performance, research/professional experience, SOP, and LOR. 3 LOR; resume/CV; SOP; transcripts; no master's degree required for PhD admission."},
        "tui": "Virtually all full-time PhD students in good progress secure a research assistantship, fellowship, or teaching assistantship providing full tuition waiver + take-home stipend + health insurance. Stipend adjusted annually for inflation; fellowship stipend increased after qualifying exam. MS students receive no departmental funding.",
        "url": "details/nu-mse-phd.html",
    },
    {
        "id": "umich-mse-phd",
        "s": "umich",
        "n": "材料科学与工程博士",
        "en": "PhD in Materials Science and Engineering (University of Michigan, Ann Arbor, College of Engineering, Department of Materials Science and Engineering; Rackham Graduate School; PhD admits direct from BS or MS; continuous support for duration of studies)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; PhD may be entered directly from BS; continuous support through fellowships, RA, TA; dissertation; minimum GPA maintained; Rackham Graduate School policy",
        "ddl": "Fall 2027 admission: **PhD deadline December 15, 2026** (MS deadline January 15, 2027). Winter (January) admission October 15, 2026 but not actively sought. PhD offers Jan-Feb; MS offers early March; rejection notifications late March.",
        "lang": "TOEFL iBT minimum 84 (MSE department minimum); ETS UMich Rackham 1839 / Department 69 (TOEFL) or 1502 (GRE); IELTS accepted; MELAB/ECPE also accepted; waivers for applicants with U.S. degree",
        "test": {"cls": "GRE NO LONGER REQUIRED for PhD (UMich MSE: 'GRE scores are no longer required to be submitted for the Ph.D. program application.' Master's applicants encouraged to submit GRE if undergraduate degree from outside North America. 3 LOR; Academic SOP (1-3 pages); Personal Statement; MSE Research Area Interest Ranking Form (PhD only); unofficial transcripts; bachelor's degree in engineering/physical science."},
        "tui": "MSE PhD students are offered continuous support for the duration of their studies through fellowships, research assistantships, and teaching assistantships. Additional consideration for Rackham and College of Engineering fellowships; national fellowship encouragement (NSF, NASA, DoD). All support contingent on satisfactory progress and funding availability.",
        "url": "details/umich-mse-phd.html",
    },
    {
        "id": "ucsd-mats-phd",
        "s": "ucsd",
        "n": "材料科学与工程博士",
        "en": "PhD in Materials Science and Engineering (UC San Diego, Jacobs School of Engineering, university-wide Program in Materials Science and Engineering, MATS; interdisciplinary faculty from Jacobs School, Physical Sciences, Scripps, School of Medicine, Skaggs Pharmacy; students must first complete MS requirements en route)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "48 units of coursework (12 courses) expected by end of second year, plus MATS Academy I/II and MATS 200 seminars; Comprehensive Exam (Spring of first year, 70% pass threshold, one retake allowed by end of second year); Qualifying Exam (Senate/UQE, oral committee of 4, within first 12 quarters); dissertation defense requiring at least one publication in referred journal",
        "ddl": "Fall 2027 admission: application opens Wednesday, September 2, 2026. **PhD deadline January 6, 2027, 11:59 pm PST** (MS deadline March 19, 2027, 11:59 pm PST). Goal to review and decide most applications before April.",
        "lang": "TOEFL iBT minimum 85 (UCSD Graduate Division); IELTS accepted; ETS UCSD 4836; scores self-reported at application, official required upon matriculation; waivers per UCSD international policy",
        "test": {"cls": "GRE OPTIONAL (not required; MATS: 'has waived the GRE test requirement for all applications... applications are evaluated as a total package.' Self-reported scores accepted; if submitted, official scores required at matriculation. Admitted students typically provide Quant 85-90 percentile (admission distribution, not threshold). No minimum score. 3+ LOR; SOP; resume; transcripts; bachelor's degree in engineering, physical sciences, or mathematics."},
        "tui": "PhD students typically receive full funding through research assistantships, teaching assistantships, and university fellowships covering tuition and stipend. MATS PhD students must maintain Faculty Advisor/PI relationship; inability to secure advisor may be grounds for dismissal.",
        "url": "details/ucsd-mats-phd.html",
    },
]

DETAIL_TEMPLATE = """<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{school} - {en}</title>
<style>
body{{font-family:-apple-system,'Segoe UI',Roboto,sans-serif;max-width:960px;margin:24px auto;padding:0 20px;color:#222;line-height:1.6}}
h1{{font-size:24px;border-bottom:2px solid #1a73e8;padding-bottom:8px}}
h2{{font-size:18px;color:#1a73e8;margin-top:24px}}
.card{{background:#f8f9fa;border-left:4px solid #1a73e8;padding:12px 16px;margin:12px 0;border-radius:4px}}
.meta{{display:grid;grid-template-columns:120px 1fr;gap:6px 12px;font-size:14px}}
.meta b{{color:#555}}
ul{{margin:6px 0;padding-left:20px}}
.note{{background:#fff3cd;border-left-color:#ffc107;padding:10px 14px;margin-top:16px;font-size:13px}}
a{{color:#1a73e8}}
</style>
</head>
<body>
<h1>{school} - {en}</h1>
<div class="card">
<div class="meta">
<b>Degree</b><span>{deg}</span>
<b>Level</b><span>Research Doctorate (PhD)</span>
<b>STEM</b><span>{stem_label}</span>
<b>Duration</b><span>{dur}</span>
<b>Deadline</b><span>{ddl}</span>
<b>Language</b><span>{lang}</span>
<b>Standardized</b><span>{test_cls}</span>
<b>Funding</b><span>{tui}</span>
</div>
</div>

<h2>Program Overview</h2>
<div class="card">
{overview}
</div>

<h2>Admissions Requirements</h2>
<div class="card">
{requirements}
</div>

<h2>Research Areas</h2>
<div class="card">
{research}
</div>

<h2>Official Source</h2>
<div class="card">
{source}
</div>

<div class="note">
<strong>Note:</strong> Second batch of Materials Science and Engineering PhD sweep (CMU, Cornell, Northwestern, UMich, UCSD MATS). Continuation from round 243 (MIT, Stanford, Berkeley, UIUC, Georgia Tech). All five programs are GRE-free or GRE-optional: CMU GRE WAIVED since Fall 2022; Cornell GRE optional; Northwestern GRE not required and not reviewed; UMich GRE no longer required for PhD; UCSD MATS GRE optional. Combined with rounds 240-242 (14 Chemical Engineering PhDs) and round 243 (5 MSE PhDs), this round brings the MSE PhD sweep to 10 of the top U.S. programs. Deadlines span December 1 (Cornell, Northwestern), December 15 (UMich), January 6 (UCSD), and January 8 (CMU). All five programs offer full funding to PhD students through RA/TA/fellowships.
</div>
</body>
</html>
"""

PAGES = {
    "cmu-mse-phd": {
        "school": "Carnegie Mellon University, Department of Materials Science and Engineering",
        "en": "PhD in Materials Science and Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1801)",
        "dur": "Typically 4-5 years; research begins intensively in second semester; MS may be earned en route; timetable set to allow graduation in four years; office space separate from laboratory; graduate student advisory committee",
        "ddl": "Fall 2027 admission: opens October 1, 2026. **PhD deadline January 8, 2027** (MS deadline January 15, 2027). Spring PhD June 15 - August 31. Fee $75 (cannot be waived or deferred). Info sessions: PhD Dec 12, Masters Dec 13.",
        "lang": "TOEFL iBT minimum 84 total (R22/L22/S18/W22); IELTS Academic minimum 6.5; Duolingo DET minimum 105; required for non-native English speakers",
        "test_cls": "GRE WAIVED for Fall 2022 cycle and later (CMU MSE old page explicitly lists 'Official GRE test scores *WAIVED for Fall 2022 applications'; new department page no longer lists GRE). 3 LOR for PhD; essay questions; CV/resume; uploaded unofficial transcripts; minimum 'B' average.",
        "tui": "PhD students at least partially funded and encouraged to apply for fellowships. Master's students self-supporting. Fee $75 cannot be waived or deferred.",
        "overview": "Carnegie Mellon's Department of Materials Science and Engineering, founded more than 100 years ago as one of the first departments at Carnegie Tech, offers MS and PhD degrees. The doctoral degree emphasizes creation of new knowledge through extensive independent research, including hypothesis formulation, interpretation of phenomena, and extraction of general principles. Research begins intensively in the second semester; the timetable is set to allow graduation in four years. All students have office space separate from the laboratory. The department offers standard MSE MS and MATSCI MS, plus specialized tracks: Computational Materials Science and Engineering (CMSE), Master of Science in Additive Manufacturing (MSAM), and Masters in Energy Science, Technology and Policy (ESTP). The PhD application period for Fall entry is October 1 through January 8; the application fee is $75 and cannot be waived or deferred. Admission requires a better than 'B' average in materials science or a related discipline at a recognized university.",
        "requirements": "<ul><li>Bachelor's degree in materials science, engineering, or related discipline at recognized university</li><li>Better than 'B' average (minimum 3.0/4.0) in prior academic record</li><li>GRE WAIVED since Fall 2022 (new page no longer lists GRE requirement)</li><li>TOEFL iBT minimum 84 total (R22/L22/S18/W22); IELTS 6.5; Duolingo DET 105</li><li>CMU online application</li><li>$75 non-refundable application fee (cannot be waived or deferred)</li><li>3 letters of recommendation (PhD); 1 required + 1 optional (MS)</li><li>Essay questions</li><li>CV/resume</li><li>Uploaded unofficial transcripts (official requested upon admission)</li><li>**PhD deadline January 8, 2027** (Fall 2027)</li><li>MS deadline January 15, 2027</li><li>Spring PhD admission June 15 - August 31</li><li>Info sessions: PhD Dec 12, Masters Dec 13</li><li>On-campus residential (Pittsburgh, PA)</li></ul>",
        "research": "<ul><li>Soft, nanostructured, and bioactive materials (tissue engineering, bioelectronics, biosensors)</li><li>Computational materials science (macroscale, mesoscale, atomic scale, quantum mechanics, interfaces, data science, ML)</li><li>Manufacturing and characterization (iron/steelmaking, additive manufacturing, 3D/high-throughput characterization, SEM/TEM, quantitative image analysis)</li><li>Inorganic materials (batteries and fuel cells, microelectronics, quantum computing, spintronics, magnetics)</li><li>Materials Innovation Cloud Lab (AI Science Foundry) - automated materials discovery for aerospace, energy, infrastructure</li><li>DOE Genesis Mission participation (AI-powered quantum/optoelectronic materials discovery)</li><li>Sustainable iron and steel production (The Business of Materials podcast)</li></ul>",
        "source": '<a href="https://mse.engineering.cmu.edu/education/graduate/apply/index.html" target="_blank">CMU MSE Graduate Apply (Fall PhD Oct 1 - Jan 8; MS Oct 1 - Jan 15; Spring PhD Jun 15 - Aug 31; fee $75; TOEFL R22/L22/S18/W22 total 84; IELTS 6.5; Duolingo 105; 3 LOR PhD; essays; CV; info sessions PhD Dec 12 / Masters Dec 13)</a> | <a href="https://www.cmu.edu/engineering/materials/graduate/application-information/index.html" target="_blank">CMU MSE Application Information (historical page: GRE WAIVED for Fall 2022; better than B average; 3 LOR; SOP; CV; transcripts; fee $75; Fall PhD Oct 1 - Dec 15; Spring PhD Jun 1 - Aug 31)</a> | <a href="https://engineering.cmu.edu/_files/documents/events/grad-info-session/MSE_CMUEngineering.pdf" target="_blank">CMU MSE Info Session PDF (research begins second semester; 4-year timetable; office space separate from lab; MS tracks MSE/MATSCI/CMSE/MSAM/ESTP; mean PhD graduate salary $90,000; max $120,000)</a>',
    },
    "cornell-mse-phd": {
        "school": "Cornell University, Duffield College of Engineering, Department of Materials Science and Engineering",
        "en": "PhD in Materials Science and Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1801)",
        "dur": "Minimum 10 semesters; Qualifying Exam Spring Y1; A Exam (candidacy) Spring Y2; B Exam (dissertation defense) Spring Y5; Responsible Conduct of Research training required; ORCID required; Student Progress Reviews begin Y2",
        "ddl": "Fall 2027: opens mid-September 2026. **PhD deadline December 1, 2026, 11:59 pm EDT** (MS deadline February 1, 2027; MEng deadline January 2 at 11:59pm EDT). All materials including LOR must be uploaded by deadline.",
        "lang": "TOEFL iBT R4 / W4 / L3.5 / S4 (Cornell Graduate School scale; does not accept 'My Best' superscore); IELTS Academic minimum 7.0; ETS Cornell 2098; department code 0000 undecided",
        "test_cls": "GRE OPTIONAL for PhD (Cornell MSE: 'The GRE is optional for our Ph.D. program. You may submit GRE results if you feel that your GRE results help to demonstrate math ability that is otherwise not demonstrated in your academic records.' No penalty for non-submission. 3 LOR through ApplyWeb; SOP; personal statement; unofficial transcripts; bachelor's in engineering or physical science.",
        "tui": "PhD students typically receive full funding through research assistantships, teaching assistantships, and fellowships (full tuition waiver + stipend + health insurance). Cornell application fee; fee waivers available for eligible applicants.",
        "overview": "Cornell's Department of Materials Science and Engineering (Duffield College of Engineering) offers MS, MEng, and PhD degrees. PhD students come from a variety of engineering and physical science backgrounds: materials science undergraduates, as well as those from mechanical engineering, chemical engineering, chemistry, and other fields. The program embraces this breadth and leverages the interdisciplinary nature of materials science. As a PhD student, the largest effort is devoted to research, supplemented by advanced graduate classes in areas selected by the student and special committee. The PhD requires a minimum of 10 semesters of graduate study. The Qualifying Exam (Q exam) is taken in the Spring of the first year; the A Exam (admission to candidacy) in the Spring of the second year; and the B Exam (dissertation defense) in the Spring of the fifth year. Responsible Conduct of Research training and ORCID are required. Student Progress Reviews begin in the second year. Applications are due December 1 at 11:59 pm EDT; the GRE is optional for the PhD.",
        "requirements": "<ul><li>Bachelor's degree in engineering or physical science</li><li>GRE OPTIONAL for PhD (no penalty for not submitting)</li><li>TOEFL iBT R4/W4/L3.5/S4; Cornell does not accept 'My Best' superscore; IELTS Academic minimum 7.0</li><li>ETS Cornell 2098; department code 0000 undecided</li><li>ApplyWeb online application</li><li>3 letters of recommendation (through ApplyWeb; institutional/company email preferred)</li><li>Academic Statement of Purpose (first paragraph 150 words summarizing topics and faculty of interest; max 2 pages)</li><li>Personal Statement (background and experiences)</li><li>Unofficial transcripts</li><li>**PhD deadline December 1, 2026, 11:59 pm EDT**</li><li>MS deadline February 1, 2027</li><li>MEng deadline January 2 at 11:59pm EDT</li><li>Q exam Spring Y1; A Exam Spring Y2; B Exam Spring Y5</li><li>Minimum 10 semesters; Responsible Conduct of Research; ORCID required</li><li>On-campus residential (Ithaca, NY)</li></ul>",
        "research": "<ul><li>Bioinspired materials and systems (bioinspired composites, engineered protein films, molecular imaging tools, biomaterials for tissue engineering and drug delivery)</li><li>Electronics and photonics (oxide semiconductors, 3D integration, materials beyond silicon, high-K/low-K dielectrics, plasmonics, spintronics, multiferroics)</li><li>Energy production and storage</li><li>Green technologies (green composites, CO2 capture and conversion)</li><li>Affiliates: Cornell Center for Materials Research (CCMR), Cornell Energy Systems Institute, Cornell Institute of Biotechnology</li></ul>",
        "source": '<a href="https://www.duffield.cornell.edu/mse/phd/phd-admission-requirements/" target="_blank">Cornell MSE PhD Admission Requirements (Dec 1 2026 11:59pm EDT; GRE optional for PhD; 3 LOR through ApplyWeb; SOP; unofficial transcripts; TOEFL per Graduate School; ETS 2098; dept code 0000; mse-admissions@cornell.edu)</a> | <a href="https://www.mse.cornell.edu/mse/programs/graduate-programs/admissions-details-requirements" target="_blank">Cornell MSE Admissions Details & Requirements (PhD Jan 2 deadline on secondary page; GRE optional for PhD and MS; no minimum score; ETS 2098; scores valid 5 years; PhD/MS/MEng tracks)</a> | <a href="https://courses.cornell.edu/programs/materials-science-engineering-phd/" target="_blank">Cornell Courses Catalog: Materials Science and Engineering PhD (CIP 14.1801; in-person Ithaca; minimum 10 semesters; RCR required; ORCID required; Q exam Spring Y1; A exam Spring Y2; B exam Spring Y5; core courses MSE 8020/8005/8010/5802/8000; TOEFL R4/W4/L3.5/S4; IELTS 7.0; no My Best superscore)</a>',
    },
    "nu-mse-phd": {
        "school": "Northwestern University, McCormick School of Engineering, Department of Materials Science and Engineering",
        "en": "PhD in Materials Science and Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1801)",
        "dur": "12 units total (up to 6 units credit for MS); 7 core MAT_SCI courses (401/402/404-1/404-2/405/406/408) + GEN_ENG 519 RCR; 2 departmental electives; 4 free electives; minimum 2 quarters TA (20 hrs/week); preliminary evaluation; qualifying exam; public oral dissertation defense; departmental seminar attendance",
        "ddl": "Fall 2027: portal opens September 10, 2026. **PhD deadline December 1, 2026, 11:59 pm (includes LOR)**. Decisions January 2027; group visits February-March; decision deadline April 15, 2027.",
        "lang": "TOEFL iBT minimum 90 for PhD (TGS minimum; MS minimum 80); IELTS Academic minimum 7.0; ETS Northwestern 1565; scores valid 5 years; waivers for English-instructed undergraduate/graduate degree",
        "test_cls": "GRE NOT REQUIRED AND NOT REVIEWED (Northwestern MSE: 'The GRE is not required for admission, nor will it be reviewed by the committee if submitted.' Evaluated on academic performance, research/professional experience, SOP, LOR. 3 LOR; resume/CV; SOP; transcripts; master's degree not required for PhD admission.",
        "tui": "Virtually all full-time PhD students in good progress secure RA/fellowship/TA providing full tuition waiver + take-home stipend + health insurance. Stipend adjusted annually; fellowship stipend increases after qualifying exam. MS students receive no departmental funding.",
        "overview": "Northwestern's Department of Materials Science and Engineering is the world's first academic department of its kind. It offers MS and PhD degrees in diverse areas of materials science including nanomaterials, biomaterials, electronic materials, metals, ceramics, and polymers, with applications in energy, sustainability, medicine, and additive manufacturing. Strong interdisciplinary collaboration is a hallmark: the department partners with other engineering and science departments, the Feinberg School of Medicine, and nearby Argonne National Laboratory. The PhD requires 12 units total (up to 6 units credit for MS). Required core courses include MAT_SCI 401 Chemical & Statistical Thermodynamics of Materials, 402 Structure of Crystalline and Noncrystalline Materials, 404-1 Fundamentals of Soft Matter, 404-2 Imperfections in Materials, 405 Physics of Solids, 406 Mechanical Properties of Materials, 408 Phase Transformations in Materials, plus GEN_ENG 519 Responsible Conduct for Research Training. The department requires a minimum of two quarters (totaling 20 hrs/week) as a teaching assistant or grader. The GRE is not required and will not be reviewed even if submitted. PhD applications are due December 1 at 11:59 pm, including letters of recommendation.",
        "requirements": "<ul><li>Bachelor's degree in materials science, engineering, physics, chemistry, or related field</li><li>GRE NOT REQUIRED AND NOT REVIEWED (even if submitted, scores not evaluated)</li><li>TOEFL iBT minimum 90 (PhD) / 80 (MS); IELTS Academic minimum 7.0; ETS Northwestern 1565</li><li>TGS online application (opens September 10)</li><li>3 letters of recommendation</li><li>Statement of purpose</li><li>Resume/CV</li><li>Transcripts</li><li>No writing sample required beyond SOP (MSE department does not require separate writing sample)</li><li>**PhD deadline December 1, 2026, 11:59 pm** (Fall 2027; includes LOR)</li><li>Decisions January 2027; group visits February-March; decision deadline April 15</li><li>MS deadline February 12</li><li>Minimum 12 units total; 7 core MAT_SCI courses; minimum 2 quarters TA</li><li>Master's degree not required for PhD admission (very few new PhD students have a master's)</li><li>On-campus residential (Evanston, IL)</li></ul>",
        "research": "<ul><li>Nanomaterials and nanotechnology</li><li>Biomaterials and medical materials (collaboration with Feinberg School of Medicine)</li><li>Electronic materials</li><li>Metals, ceramics, and polymers</li><li>Energy materials and sustainability</li><li>Additive manufacturing</li><li>Interdisciplinary collaboration with Argonne National Laboratory</li></ul>",
        "source": '<a href="https://www.mccormick.northwestern.edu/materials-science/academics/graduate/phd/admissions.html" target="_blank">Northwestern MSE PhD Admissions (Dec 1 11:59pm includes LOR; GRE not required and not reviewed; TOEFL iBT 90 / IELTS 7.0; RA/fellowship full tuition + stipend + health insurance; decisions Jan; group visits Feb-Mar; April 15 decision deadline)</a> | <a href="https://www.tgs.northwestern.edu/admission/academic-programs/explore-programs/materials-science-and-engineering.html" target="_blank">Northwestern TGS: Materials Science and Engineering PhD (12 units total; up to 6 units MS credit; core MAT_SCI 401/402/404-1/404-2/405/406/408 + GEN_ENG 519; 2 dept electives; 4 free electives; min 2 quarters TA; preliminary evaluation; qualifying exam; public oral defense; updated Aug 28, 2026)</a> | <a href="https://www.mccormick.northwestern.edu/materials-science/academics/graduate/financial-aid.html" target="_blank">Northwestern MSE Financial Aid (virtually all full-time PhD in good progress secure RA/fellowship/TA with stipend + full tuition; MS no departmental funding; stipend adjusted annually; fellowship stipend increases after qualifying)</a>',
    },
    "umich-mse-phd": {
        "school": "University of Michigan, Department of Materials Science and Engineering",
        "en": "PhD in Materials Science and Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1801)",
        "dur": "Typically 5-6 years; direct BS-to-PhD entry allowed; continuous support through fellowships/RA/TA; dissertation; Rackham Graduate School policy; minimum GPA maintained",
        "ddl": "Fall 2027: **PhD deadline December 15, 2026** (MS deadline January 15, 2027). Winter (January) admission October 15 but not actively sought. PhD offers Jan-Feb; MS offers early March; rejection notifications late March.",
        "lang": "TOEFL iBT minimum 84 (MSE department minimum); ETS UMich Rackham 1839 / Department 69 (TOEFL) or 1502 (GRE); IELTS/MELAB/ECPE accepted; waivers for U.S. degree",
        "test_cls": "GRE NO LONGER REQUIRED for PhD (UMich MSE: 'GRE scores are no longer required to be submitted for the Ph.D. program application.' Master's applicants encouraged to submit GRE if undergraduate degree from outside North America. 3 LOR; Academic SOP 1-3 pages; Personal Statement; MSE Research Area Interest Ranking Form (PhD only); unofficial transcripts.",
        "tui": "MSE PhD students offered continuous support for duration of studies through fellowships, RA, TA. Additional consideration for Rackham and College of Engineering fellowships; national fellowship encouragement (NSF, NASA, DoD). All support contingent on satisfactory progress and funding availability.",
        "overview": "The University of Michigan Department of Materials Science and Engineering (Ann Arbor) offers MS and PhD degrees administered through the Rackham Graduate School. The PhD is directed at students hoping to pursue research careers in academia, industry, or national labs. Students may enter directly from a bachelor's degree (without a master's). The MSE Research Area Interest Ranking Form is required for PhD applicants only. PhD students are offered continuous support for the duration of their studies through fellowships, research assistantships, and teaching assistantships; applicants are also considered for Rackham and College of Engineering fellowships and encouraged to apply for nationally competitive fellowships (NSF, NASA, DoD). The PhD deadline is December 15 for Fall admission; the MS deadline is January 15. The GRE is no longer required for the PhD. Decisions are typically made between the beginning and end of January and continue through April. The department contact is Renee Hilgendorf (reneeh@umich.edu).",
        "requirements": "<ul><li>Bachelor's degree in materials science, engineering, physics, chemistry, or related field</li><li>GRE NO LONGER REQUIRED for PhD application</li><li>MS applicants encouraged to submit GRE if undergraduate degree from outside North America</li><li>TOEFL iBT minimum 84; ETS Rackham 1839 / Dept 69 (TOEFL) or 1502 (GRE); IELTS/MELAB/ECPE accepted</li><li>Rackham Graduate School online application (ApplyWeb)</li><li>3 letters of recommendation (strongly recommended to determine before starting application)</li><li>Academic Statement of Purpose (1-3 pages, 12pt font, single-spaced, 1-inch margins)</li><li>Personal Statement (background and experiences)</li><li>MSE Research Area Interest Ranking Form (PhD only)</li><li>Transcripts (uploaded scanned copy; official after offer)</li><li>**PhD deadline December 15, 2026** (Fall 2027)</li><li>MS deadline January 15, 2027</li><li>Winter (January) admission October 15 but not actively sought</li><li>PhD offers Jan-Feb; MS offers early March; rejections late March</li><li>On-campus residential (Ann Arbor, MI)</li></ul>",
        "research": "<ul><li>Metals, ceramics, polymers, and electronic materials</li><li>Materials for energy and sustainability</li><li>Biomaterials and medical materials</li><li>Computational materials science</li><li>Advanced manufacturing and characterization</li><li>Collaboration with Michigan Engineering affiliates</li></ul>",
        "source": '<a href="https://mse.engin.umich.edu/graduate/admissions/application-faq/" target="_blank">UMich MSE Application FAQ (PhD GRE no longer required; TOEFL iBT minimum 84; PhD Dec 15 / MS Jan 15; Winter Oct 15; continuous support; ETS 1839/69; decisions Jan-April; contact reneeh@umich.edu)</a> | <a href="https://mse.engin.umich.edu/graduate/admissions/" target="_blank">UMich MSE Applying (PhD Dec 15 Fall / MS Jan 15; 3 LOR; Academic SOP 1-3 pages; Personal Statement; Research Area Interest Ranking Form PhD only; uploaded scanned transcripts; TOEFL 1839/69; PhD offers Jan-Feb, MS early March, rejections late March)</a> | <a href="https://www.engin.umich.edu/admissions/graduate-professional/deadlines/" target="_blank">Michigan Engineering Graduate Deadlines (MSE PhD Dec 15 / MS Jan 15; Rackham-administered; winter Oct 15)</a>',
    },
    "ucsd-mats-phd": {
        "school": "UC San Diego, Program in Materials Science and Engineering (MATS)",
        "en": "PhD in Materials Science and Engineering",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Engineering / CIP 14.1801)",
        "dur": "48 units coursework (12 courses) by end of second year + MATS Academy I/II + MATS 200 seminars; Comprehensive Exam Spring Y1 (70% pass, one retake by end of Y2); Qualifying Exam (Senate/UQE, oral committee of 4, within first 12 quarters); dissertation defense requiring at least one publication in referred journal; must maintain Faculty Advisor/PI",
        "ddl": "Fall 2027: application opens Wednesday, September 2, 2026. **PhD deadline January 6, 2027, 11:59 pm PST** (MS deadline March 19, 2027, 11:59 pm PST). Goal to review and decide most applications before April.",
        "lang": "TOEFL iBT minimum 85 (UCSD Graduate Division); IELTS accepted; ETS UCSD 4836; scores self-reported at application, official required upon matriculation; waivers per UCSD international policy",
        "test_cls": "GRE OPTIONAL (MATS: 'has waived the GRE test requirement for all applications... applications are evaluated as a total package.' Self-reported accepted; if submitted, official required at matriculation. Admitted typically Quant 85-90 percentile (admission distribution, not threshold). No minimum score. 3+ LOR; SOP; resume; transcripts; bachelor's in engineering, physical sciences, or math.",
        "tui": "PhD students typically receive full funding through RA/TA and university fellowships covering tuition and stipend. MATS PhD students must maintain Faculty Advisor/PI relationship; inability to secure advisor may be grounds for dismissal.",
        "overview": "The UC San Diego Program in Materials Science and Engineering (MATS) is a university-wide interdisciplinary program with faculty from the Jacobs School of Engineering, the School of Physical Sciences, Scripps Institution of Oceanography, the School of Medicine, and the Skaggs School of Pharmacy and Pharmaceutical Sciences. Undergraduate preparation for MS/PhD normally includes a degree in materials science, or in engineering/physical sciences such as physics, chemistry, biology, geology, and related disciplines. The PhD program requires 48 units of coursework (12 courses) by the end of the second academic year, plus MATS Academy I and II and MATS 200 seminars. The doctoral program has three required examinations: (1) Comprehensive Exam during the Spring quarter of the first year, requiring a 70% passing grade and retake only once before end of second year; (2) Qualifying Exam (Senate Exam/UQE), an oral committee of four (two affiliated with MATS), taken within the first twelve quarters; (3) Dissertation Defense, requiring original work leading to publication of at least one significant article in an appropriate referred journal. The GRE is optional/waived; admitted students typically provide Quant scores in the 85-90 percentile range. PhD applications are due January 6, 2027 at 11:59 pm PST.",
        "requirements": "<ul><li>Bachelor's degree in materials science, engineering, physical sciences, or mathematics</li><li>GRE OPTIONAL (not required; self-reported at application, official if submitted at matriculation)</li><li>Admitted typically Quant 85-90 percentile (admission distribution, not threshold; no minimum)</li><li>TOEFL iBT minimum 85 (UCSD Graduate Division); IELTS accepted; ETS UCSD 4836</li><li>UCSD Graduate Division online application (opens September 2, 2026)</li><li>3+ letters of recommendation</li><li>Statement of purpose</li><li>Resume/CV</li><li>Transcripts</li><li>**PhD deadline January 6, 2027, 11:59 pm PST** (Fall 2027)</li><li>MS deadline March 19, 2027, 11:59 pm PST</li><li>Comprehensive Exam Spring Y1 (70% pass); Senate/UQE within 12 quarters; dissertation defense</li><li>48 units coursework by end of second year</li><li>Must maintain Faculty Advisor/PI (switching labs must inform current PI and MATS advising)</li><li>On-campus residential (La Jolla, CA)</li></ul>",
        "research": "<ul><li>Biomaterials and medical materials</li><li>Electronic, photonic, and magnetic materials</li><li>Energy materials (batteries, solar, thermoelectrics)</li><li>Nanomaterials and nanodevices</li><li>Polymers and soft matter</li><li>Computational materials science</li><li>Interdisciplinary faculty across Jacobs, Physical Sciences, Scripps, School of Medicine, Skaggs Pharmacy</li></ul>",
        "source": '<a href="https://matsci.ucsd.edu/admissions" target="_blank">UCSD MATS Admissions (Fall 2027 opens Sep 2, 2026; PhD deadline Jan 6 2027 11:59pm PST; MS Mar 19 2027; GRE not required/optional; self-reported accepted; admitted Quant 85-90 percentile admission distribution; ETS 4836; holistic review)</a> | <a href="https://catalog.ucsd.edu/curric/MATS.html" target="_blank">UCSD Catalog: Materials Science and Engineering Program (interdisciplinary faculty; MS Plan II comprehensive exam; PhD requires MS completion incl. thesis or comprehensive exam; MATS qualifying exam Senate exam; three doctoral exams; dissertation)</a> | <a href="https://matsci.ucsd.edu/graduate-studies/doctoral-program" target="_blank">UCSD MATS Doctoral Program (48 units / 12 courses by end of Y2 + MATS Academy I/II + MATS 200; Comprehensive Exam 70% pass; Senate/UQE oral committee of 4; dissertation defense; pre-Fall 2024 checklist with MATS 201A/B/C, 227, electives MATS 205A/213A/231/236/251A/251B/252/253/254/255/256/257/261A/261B/269/PHYS 152A; MATS 200 six quarters; faculty advisor policy)</a>',
    },
}

# Write detail pages
for p in PROGRAMS:
    key = p["id"]
    d = PAGES[key]
    html = DETAIL_TEMPLATE.format(
        school=d["school"], en=d["en"], deg=d["deg"], stem_label=d["stem_label"],
        dur=d["dur"], ddl=d["ddl"], lang=d["lang"], test_cls=d["test_cls"], tui=d["tui"],
        overview=d["overview"], requirements=d["requirements"],
        research=d["research"], source=d["source"],
    )
    path = os.path.join(DET, key + ".html")
    with open(path, "w", encoding="utf-8") as f:
        f.write(html)
    print(f"Wrote: {key}.html")

# Append PROGRAMS
idx_path = os.path.join(BASE, "index_main.html")
with open(idx_path, "r", encoding="utf-8") as f:
    html = f.read()

def build_entry(p):
    return ('{{id:"{id}",s:"{s}",n:"{n}",en:"{en}",deg:"{deg}",lvl:"{lvl}",stem:{stem},'
            'dur:"{dur}",ddl:"{ddl}",lang:"{lang}",test:{{cls:"{test_cls}"}},'
            'tui:"{tui}",url:"{url}"}}').format(
        id=p["id"], s=p["s"], n=p["n"], en=p["en"], deg=p["deg"], lvl=p["lvl"],
        stem=p["stem"], dur=p["dur"], ddl=p["ddl"], lang=p["lang"],
        test_cls=p["test"]["cls"].replace('"', "'"),
        tui=p["tui"].replace('"', "'"), url=p["url"],
    )

new_entries = ",\n".join(build_entry(p) for p in PROGRAMS)

m = re.search(r'const\s+PROGRAMS\s*=\s*\[', html)
start = m.end()
depth = 1
i = start
while i < len(html) and depth > 0:
    c = html[i]
    if c == '[': depth += 1
    elif c == ']': depth -= 1
    i += 1
insert_pos = i - 1
prefix = html[:insert_pos].rstrip()
suffix = html[insert_pos:]
if prefix.endswith('{'):
    new_block = prefix + "\n" + new_entries + "\n" + suffix
else:
    new_block = prefix + ",\n" + new_entries + "\n" + suffix

# Append VD on new_block (re-locate to avoid offset)
vd_entries = ",\n".join(f'"{p["url"]}"' for p in PROGRAMS)
m2 = re.search(r'VERIFIED_DETAILS\s*=\s*new\s+Set\s*\(\s*\[', new_block)
vstart = m2.end()
vdepth = 1
j = vstart
while j < len(new_block) and vdepth > 0:
    c = new_block[j]
    if c == '[': vdepth += 1
    elif c == ']': vdepth -= 1
    j += 1
vinsert_pos = j - 1
vprefix = new_block[:vinsert_pos].rstrip()
vsuffix = new_block[vinsert_pos:]
if vprefix.endswith(','):
    new_block = vprefix + "\n" + vd_entries + "\n" + vsuffix
elif vprefix.endswith('['):
    new_block = vprefix + "\n" + vd_entries + "\n" + vsuffix
else:
    new_block = vprefix + ",\n" + vd_entries + "\n" + vsuffix

with open(idx_path, "w", encoding="utf-8") as f:
    f.write(new_block)

print(f"Appended {len(PROGRAMS)} PROGRAMS entries and {len(PROGRAMS)} VD entries")
print(f"Done. File size: {os.path.getsize(idx_path)}")
