# -*- coding: utf-8 -*-
"""Round 254: batch add 5 Physics PhD (fourth tier)
- Notre Dame Physics PhD (Dec 15, 2026; GRE General NOT accepted; GRE Subject NOT accepted; TOEFL/IELTS/Duolingo; ETS 1841; ~120 grad students / 68 faculty; 100% full tuition + stipend + health insurance; 2-year minimum residency; interdisciplinary MSE doctoral program via Physics Dept)
- Rice Physics & Astronomy PhD (Dec 15, 2026 11:59 EST; late apps until April 1, 2027; open Sept 1, 2026; GRE General NOT required/made use of; GRE Subject NOT required/made use of; ~110 grad students; all enter PhD directly no terminal MS; 8 approved grad courses; oral candidacy; no foreign language; no comprehensive written qual. Note: Rice Applied Physics (Smalley-Curl) is SEPARATE program Dec 31)
- Vanderbilt Physics PhD (Dec 1, 2026; open Aug 1, 2026; GRE NOT required General nor Subject submitted; 3+ LOR; SOP 1000-2000 words; ETS 1871. Note: Vanderbilt Astrophysics PhD is SEPARATE Dec 7, 2026)
- Brown Physics PhD (Dec 15, 2026; open Sept 8, 2026; Physics track: GRE Subject REQUIRED (waived if master's in physics); General optional; Astrophysics track: Subject NOT considered; TOEFL recommended 90 iBT/577 paper; IELTS 7.0; ETS 3094; Physics code 76 for TOEFL. Note: Brown Applied Math Division is SEPARATE PhD)
- Duke Physics PhD (Dec 1, 2026 11:59:59pm EST; GRE General optional; GRE Subject optional; matriculating average V159/Q166/AW3.5 and Physics Subject 700+ (admission distribution, not minimum threshold); TOEFL 90; IELTS 7.0; 3 LOR; ~116 grad students / 45 faculty; 100% financial aid; 300+ applicants per year)
Key finding: fourth tier is predominantly GRE-free/not accepted (Notre, Rice, Vanderbilt fully not required/accepted; Duke optional; Brown Physics track is the outlier - still requires Physics Subject for Physics track, with waiver if master's in physics).
"""
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": "notre-physics-phd",
        "s": "notre",
        "n": "物理博士",
        "en": "PhD in Physics (University of Notre Dame, Department of Physics and Astronomy, Graduate School; located in Notre Dame, IN; ~120 graduate students / 68 faculty; offers interdisciplinary Materials Science and Engineering doctoral degree via Physics Dept)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; 2-year minimum residency; core courses; preliminary and qualifying exams; teaching assistantships during academic year; research assistantships in summer; dissertation; on-campus residential (Notre Dame, IN); Fall admission primarily",
        "ddl": "Fall 2027 (2027-28 cycle): **Deadline December 15, 2026** (full consideration). Applications evaluated by physics and astronomy admissions committee of 10 faculty; selected applicants invited to online interview; chair makes final decision; official offer sent by Graduate School. Application fee per Graduate School.",
        "lang": "TOEFL iBT / IELTS Academic / Duolingo English Test required for non-native English speakers. ETS institution code 1841 (used for both GRE and TOEFL). Unofficial English proficiency scores accepted at application; official scores required upon admission.",
        "test": {"cls": "GRE GENERAL TEST NOT ACCEPTED; GRE SUBJECT TEST NOT ACCEPTED (Notre Dame Physics: 'The Subject and General GRE scores are not required or accepted for applications in 2025. The Graduate School Degree Programs page for Physics PhD explicitly lists GRE General Test not accepted; GRE Subject Test not accepted.' 3 LOR; CV; Statement of Intent; unofficial transcripts from each post-secondary institution; official transcript showing bachelor's degree conferral due upon enrollment.)"},
        "tui": "Notre Dame Physics: 100% of admitted graduate students receive full tuition support, a competitive stipend, and full medical insurance subsidy. Beginning doctoral students typically work as teaching assistants (~15 hours/week) during the academic year; most hold research assistantships in summer. Strong academic records automatically considered for fellowships. APS cites Notre Dame Physics as female-friendly department with ~30% female graduate students.",
        "url": "details/notre-physics-phd.html",
    },
    {
        "id": "rice-physics-phd",
        "s": "rice",
        "n": "物理博士",
        "en": "PhD in Physics and Astronomy (Rice University, Wiess School of Natural Sciences, Department of Physics and Astronomy; located in Houston, TX; ~110 graduate students, 15-20 new students per year; all students enter PhD directly - no terminal MS; separate from Applied Physics Smalley-Curl Institute PhD)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; at least 8 approved graduate courses; oral PhD candidacy examination; no comprehensive written qualifying exam; no foreign language requirement; dissertation research; on-campus residential (Houston, TX); Fall admission only",
        "ddl": "Fall 2027: **Deadline December 15, 2026, 11:59 p.m. EST**. Application system opens Tuesday, September 1, 2026. Late applications may be considered until April 1, 2027 but candidates missing the deadline place themselves in a less competitive position. Application timestamped Eastern Time. Note: Rice Applied Physics Graduate Program (Smalley-Curl Institute) has separate December 31, 2026 deadline - this entry is Physics and Astronomy, NOT Applied Physics.",
        "lang": "TOEFL iBT / IELTS Academic required for non-native English speakers per Rice Graduate and Postdoctoral Studies. ETS institution code 4822 (Rice). TOEFL and IELTS requirements may be waived for students who have received a degree from a university where English is the official language of communication. International students admitted to the program must provide proof of financial support.",
        "test": {"cls": "GRE GENERAL NEITHER REQUIRED NOR MADE USE OF; GRE PHYSICS SUBJECT NEITHER REQUIRED NOR MADE USE OF (Rice Physics: 'Our department neither requires nor makes use of the GRE subject test in physics or the general GRE exam. The absence of GRE scores will not affect your application in any way. The admissions website provides the opportunity to submit GRE scores if you have taken the test and feel that your scores would provide important information that would strengthen your application.' 3 LOR; research statement; transcripts; CV.)"},
        "tui": "Rice Physics and Astronomy PhD students typically receive multi-year fully-funded support through a combination of Research Assistantships, Teaching Assistantships, and fellowships, including tuition, stipend, and health insurance. Department enrollment ~110 graduate students with 15-20 entering each year; all students admitted directly to PhD program (no terminal MS).",
        "url": "details/rice-physics-phd.html",
    },
    {
        "id": "vanderbilt-physics-phd",
        "s": "vanderbilt",
        "n": "物理博士",
        "en": "PhD in Physics (Vanderbilt University, College of Arts and Science, Department of Physics and Astronomy; Graduate School; located in Nashville, TN; separate from Vanderbilt Astrophysics PhD which has its own December 7 deadline)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; coursework; preliminary and qualifying exams; candidacy; dissertation; on-campus residential (Nashville, TN); Fall admission only; initial offers by March 31 with response due April 15",
        "ddl": "Fall 2027: **Deadline December 1, 2026**. Applications open August 1, 2026 and submitted through Graduate School Application Portal. Most programs release initial Fall admission offers by March 31 with a response due by April 15. Note: Vanderbilt Astrophysics PhD has separate December 7, 2026 deadline - this entry is Physics, NOT Astrophysics.",
        "lang": "TOEFL iBT / IELTS Academic / Duolingo English Test required for non-native English speakers per Vanderbilt Graduate School language proficiency waiver policy. ETS institution code 1871 (no department code needed; if ETS requires department code, select any listed - scores will come to Graduate School). Scores valid within 5 years to month of intended first term.",
        "test": {"cls": "GRE GENERAL NOT REQUIRED; GRE PHYSICS SUBJECT NOT REQUIRED (Vanderbilt Physics: 'Do not submit GRE scores (General nor Subject). They are not required and will not be considered.' Graduate School program table lists Physics PhD as GRE Exempt. 3+ LOR; Statement of Purpose 1000-2000 words; unofficial transcripts; CV.)"},
        "tui": "Vanderbilt Physics PhD students typically receive multi-year fully-funded support through a combination of Research Assistantships, Teaching Assistantships, and Graduate School fellowships, including tuition, stipend, and health insurance. 100% of PhD students receive financial aid per Graduate School program listing.",
        "url": "details/vanderbilt-physics-phd.html",
    },
    {
        "id": "brown-physics-phd",
        "s": "brown",
        "n": "物理博士",
        "en": "PhD in Physics (Brown University, Department of Physics; Graduate School; located in Providence, RI; two tracks - Physics and Astrophysics - must select one at application; separate from Brown Applied Math Division PhD which has separate December 9 deadline)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; core courses; qualifying exams; teaching requirement; candidacy; dissertation; on-campus residential (Providence, RI); Fall admission only",
        "ddl": "Fall 2027: **Deadline December 15, 2026** (11:59 p.m. Eastern). Application opens September 8, 2026. Note: This is Physics track; Brown Applied Math Division PhD has separate December 9, 2026 deadline and requires General GRE - this entry is Physics, NOT Applied Math.",
        "lang": "TOEFL iBT / IELTS Academic required for non-native English speakers. Recommended minimum TOEFL 90 iBT (577 paper-based); recommended minimum IELTS overall band 7.0. Brown ETS institution code 3094; Physics code for TOEFL reporting: 76. Self-reported TOEFL scores accepted for initial review; official scores required upon admission.",
        "test": {"cls": "PHYSICS TRACK: GRE PHYSICS SUBJECT REQUIRED (waived if applicant already holds master's degree in physics or related field); GENERAL GRE OPTIONAL. ASTROPHYSICS TRACK: GRE PHYSICS SUBJECT NOT CONSIDERED; GENERAL GRE OPTIONAL (Brown Physics: 'For the Physics track, GRE subject scores are required. For the Astrophysics track, the GRE subject will not be considered. The general GRE is optional for both tracks. The GRE Subject Test score requirement is waived for applicants who have a master's degree in physics or a related field.') 3 LOR; CV; textbook/course list; SOP."},
        "tui": "Brown Physics PhD students typically receive multi-year fully-funded support through a combination of Research Assistantships, Teaching Assistantships, and Graduate School fellowships, including tuition, stipend, and health insurance. Note: Brown also offers a tuition-based ScM (Master of Science) program separate from the funded PhD; students admitted to ScM cannot automatically transition to PhD.",
        "url": "details/brown-physics-phd.html",
    },
    {
        "id": "duke-physics-phd",
        "s": "duke",
        "n": "物理博士",
        "en": "PhD in Physics (Duke University, Trinity College of Arts and Sciences, Department of Physics; Graduate School; located in Durham, NC; ~116 graduate students / 45 faculty; 100% financial aid; typically admits only most exceptional candidates from 300+ applicants per year)",
        "deg": "PhD",
        "lvl": "d",
        "stem": 1,
        "dur": "Typically 5-6 years; core courses in mathematical methods, classical mechanics, quantum mechanics, statistical mechanics, electrodynamics; approved electives; preliminary examination (including proposed PhD thesis research plan); dissertation; on-campus residential (Durham, NC); Fall admission only; students decide on research group by end of fourth semester",
        "ddl": "Fall 2027: **Deadline December 1, 2026, 11:59:59 p.m. EST**. All application materials (including LORs) should be received by this date for full consideration. Duke Graduate School deadline table confirms Physics PhD 12/01/2026.",
        "lang": "TOEFL iBT minimum 90 (internet-based); IELTS minimum overall 7.0. Duolingo English Test also accepted per Graduate School. ETS institution code 5116. Test waiver may apply for some applicants per Graduate School policy.",
        "test": {"cls": "GRE GENERAL OPTIONAL; GRE PHYSICS SUBJECT OPTIONAL (Duke Physics: 'Submission of general and/or Physics subject GRE scores is optional. Applicants who do not submit GRE scores will receive full consideration. Nonetheless, the submission of GRE scores may be advantageous in certain circumstances by providing additional information not conveyed by other application materials. While there are no acceptable minimum scores, matriculating students average 159 verbal, about 166 quantitative, and 3.5 in writing. The GRE Physics is recommended but not required; matriculating students typically receive a score of 700 or above. Admission distribution, not minimum threshold. 3+ LOR; SOP; CV; transcripts.)"},
        "tui": "Duke Physics: 100% of PhD students receive financial aid. Students typically receive multi-year fully-funded support through a combination of Research Assistantships, Teaching Assistantships, and Graduate School fellowships, including tuition, stipend, and health insurance. The department is highly selective: ~300+ applicants per year, admits only most exceptional candidates. Students may have advisors outside the department (if doing Physics); collaborations with other departments possible.",
        "url": "details/duke-physics-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> Fourth batch of Physics PhD sweep (Notre Dame, Rice, Vanderbilt, Brown, Duke). Key finding: fourth tier is predominantly GRE-free/not accepted (Notre Dame neither required nor accepted; Rice neither required nor made use of; Vanderbilt explicitly says do not submit; Duke both optional; Brown Physics track is the outlier - still requires Physics Subject for Physics track, with waiver if master's in physics). Important distinctions: (1) Notre Dame Physics admits through Department of Physics and Astronomy; interdisciplinary Materials Science and Engineering doctoral degree is a separate option via Physics Dept (home dept requirements + 9 hours materials courses + materials-focused thesis). (2) Rice Physics and Astronomy (Dec 15) is NOT the same as Rice Applied Physics Smalley-Curl Institute (Dec 31, fee waived, General optional with average Q164/V156, Subject recommended but not required). (3) Vanderbilt Physics (Dec 1) is NOT the same as Vanderbilt Astrophysics (Dec 7). (4) Brown Physics track (Dec 15) requires Physics Subject (waived if master's in physics); Astrophysics track does not consider Subject; General optional for both. Brown Applied Math Division is a separate PhD (Dec 9, General required, Subject highly recommended). (5) Duke Physics (Dec 1) both optional; matriculating students average V159/Q166/AW3.5 and Physics Subject 700+ - admission distribution, not minimum threshold.
</div>
</body>
</html>
"""

PAGES = {
    "notre-physics-phd": {
        "school": "University of Notre Dame, Department of Physics and Astronomy",
        "en": "PhD in Physics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Typically 5-6 years; 2-year minimum residency; core courses; preliminary and qualifying exams; TAships during academic year; RAs in summer; dissertation; on-campus (Notre Dame, IN); Fall admission primarily",
        "ddl": "Fall 2027: **Deadline December 15, 2026** (full consideration). Online interview after initial screening; official offer sent by Graduate School.",
        "lang": "TOEFL iBT / IELTS / Duolingo required for non-native English speakers. ETS institution 1841 (both GRE and TOEFL). Unofficial scores accepted at application; official upon admission.",
        "test_cls": "GRE GENERAL NOT ACCEPTED; GRE SUBJECT NOT ACCEPTED (Graduate School Degree Programs page: 'GRE General Test not accepted; GRE Subject Test not accepted'. Department page: 'The Subject and General GRE scores are not required or accepted for applications.')",
        "tui": "100% full tuition support + competitive stipend + full medical insurance subsidy. Beginning doctoral students typically TAs (~15 hrs/week) during academic year; most hold RAs in summer. Strong academic records automatically considered for fellowships.",
        "overview": "The University of Notre Dame Department of Physics and Astronomy, within the Graduate School, offers the Doctor of Philosophy (PhD) in Physics. The application deadline for full consideration is December 15. The department admits primarily students who start in the fall. Applications are evaluated by a physics and astronomy admissions committee consisting of 10 faculty members who represent the primary research areas of the department plus the graduate student coordinator. Applications are evaluated based on academic preparation and performance, research experience, letters of recommendation, statement of intent, and alignment with the department's research directions. Additionally, selected applicants will be invited to participate in an online interview, after which final candidates for admission will be recommended to the department chair. The department chair reviews the recommendations and makes the final decisions. If the decision is positive, candidates are informed that the department has recommended them to the Graduate School for admission. The official admission offer is then sent to the candidates by the Graduate School. CRITICAL POLICY: Per the Graduate School Degree Programs page (last updated 09/28/2026), Physics PhD lists GRE General Test not accepted and GRE Subject Test not accepted. The department application page states: The Subject and General GRE scores are not required or accepted for applications. Required materials include: three letters of recommendation, Statement of Intent, CV or Resume, transcripts (unofficial; official transcript showing bachelor's degree conferral due upon enrollment), and English Proficiency Examination (TOEFL or IELTS) for all students who were not educated in English. The ETS institution code for both GRE and TOEFL exams is 1841. The department has approximately 120 graduate students collaborating with 68 faculty members and ~30 postdoctoral researchers. All admitted students receive full tuition support and a stipend. Beginning doctoral students typically work as teaching assistants (about 15 hours per week) during the academic year; during the summer most students hold research assistantships. The majority of advanced students work as research assistants funded by external research grants. Applicants with strong academic records are automatically considered for fellowships. The APS cites the Notre Dame Department of Physics and Astronomy as a female-friendly physics department with ~33% female graduate students. The department is one of seven departments and programs at Notre Dame that offers the interdisciplinary Materials Science and Engineering doctoral degree. Incoming students interested in that option follow the department's admissions process; to complete the MSE degree, students must complete their home department requirements, nine hours of materials science courses, and a materials science-focused doctoral thesis, earning a 'Physics: Materials Science and Engineering' degree. The department is located in Notre Dame, Indiana.",
        "requirements": "<ul><li>Bachelor's degree in physics or related quantitative field</li><li>GRE General Test: NOT accepted (per Graduate School degree programs page)</li><li>GRE Subject Test: NOT accepted (per Graduate School degree programs page)</li><li>TOEFL iBT / IELTS / Duolingo required for non-native English speakers</li><li>ETS institution code 1841 (both GRE and TOEFL)</li><li>Graduate School online application</li><li>Statement of Intent</li><li>Three letters of recommendation</li><li>CV/Resume</li><li>Unofficial transcripts from each post-secondary institution required at application</li><li>Official transcript showing bachelor's degree conferral due upon enrollment</li><li>**Deadline December 15, 2026** for full consideration</li><li>Fall admission primarily</li><li>2-year minimum residency required</li><li>Online interview for selected applicants</li><li>100% of admitted students receive full tuition + stipend + health insurance</li><li>Interdisciplinary Materials Science and Engineering doctoral degree option via Physics Dept</li><li>On-campus residential (Notre Dame, IN)</li></ul>",
        "research": "<ul><li>Astrophysics and cosmology</li><li>Biological physics / biophysics</li><li>Experimental condensed matter physics and materials physics</li><li>Theoretical condensed matter physics</li><li>High energy physics / particle physics</li><li>Nuclear physics</li><li>Network science and complex systems</li><li>Interdisciplinary materials science (MSE doctoral degree option)</li><li>Interdisciplinary research with Notre Dame Centers for Astrophysics, Nano Science, Rare Isotope Beams, and other institutes</li></ul>",
        "source": '<a href="https://graduateschool.nd.edu/degree-programs/physics-phd---doctoral/" target="_blank">Notre Dame Graduate School: Physics PhD (Dec 15 deadline; GRE General not accepted; GRE Subject not accepted; TOEFL/IELTS/Duolingo; 3 LOR; CV; Statement of intent; unofficial transcripts; 2-year minimum residency; last updated 09/28/2026)</a> | <a href="https://physics.nd.edu/graduate/apply/" target="_blank">Notre Dame Physics Apply (Subject and General GRE not required or accepted; 3 LOR; Statement of Intent; CV; unofficial transcripts; English proficiency; Dec 15 full consideration; online interview; chair makes final decisions)</a> | <a href="https://physics.nd.edu/graduate/" target="_blank">Notre Dame Physics Graduate Overview (~120 grad students; 68 faculty; ~30 postdocs; 100% full tuition + stipend + medical insurance subsidy; TA ~15 hrs/week; RA in summer; ~33% female grad students; APS female-friendly department)</a> | <a href="https://graduateschool.nd.edu/admissions/faq/" target="_blank">Notre Dame Graduate School FAQ (ETS institution code 1841; some programs require GRE; GRE waiver via email to program contact; no minimum GRE scores; TOEFL/IELTS min scores depend on test type)</a> | <a href="https://physics.nd.edu/graduate/current-students/" target="_blank">Notre Dame Physics Current Students (interdisciplinary MSE doctoral degree via Physics Dept: home dept requirements + 9 hrs materials courses + materials-focused thesis; 2026-2027 Graduate Student Guide)</a>',
    },
    "rice-physics-phd": {
        "school": "Rice University, Wiess School of Natural Sciences, Department of Physics and Astronomy",
        "en": "PhD in Physics and Astronomy",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Typically 5-6 years; at least 8 approved graduate courses; oral PhD candidacy exam; no comprehensive written qualifying exam; no foreign language requirement; dissertation; on-campus (Houston, TX); Fall admission only",
        "ddl": "Fall 2027: **Deadline December 15, 2026, 11:59 p.m. EST**. Application system opens Tuesday, September 1, 2026. Late apps may be considered until April 1, 2027 but less competitive. Note: Rice Applied Physics Smalley-Curl PhD has separate December 31 deadline.",
        "lang": "TOEFL iBT / IELTS required for non-native English speakers. ETS institution code 4822 (Rice). TOEFL/IELTS may be waived for degrees from English-official-language universities. International students must provide proof of financial support.",
        "test_cls": "GRE GENERAL NEITHER REQUIRED NOR MADE USE OF; GRE PHYSICS SUBJECT NEITHER REQUIRED NOR MADE USE OF (Rice Physics: 'Our department neither requires nor makes use of the GRE subject test in physics or the general GRE exam. The absence of GRE scores will not affect your application in any way.')",
        "tui": "Multi-year fully-funded through RA/TA/fellowship: tuition + stipend + health insurance. ~110 graduate students, 15-20 entering per year; all students enter PhD directly (no terminal MS).",
        "overview": "The Rice University Department of Physics and Astronomy, within the Wiess School of Natural Sciences, offers the Doctor of Philosophy (PhD) in Physics and Astronomy. For Fall 2027 admissions, the application system is available from Tuesday, September 1, 2026, with an application deadline of December 15, 2026, 11:59 p.m. Eastern Time. Late applications may be considered until April 1, 2027, but candidates that miss the deadline place themselves in a less competitive position. Applications submitted are time-stamped Eastern Time. CRITICAL POLICY: Our department neither requires nor makes use of the GRE subject test in physics or the general GRE exam. The absence of GRE scores will not affect your application in any way. The admissions website provides the opportunity to submit GRE scores if applicants have taken the test and feel that their scores would provide important information that would strengthen the application. Three letters of recommendation are required; letters are usually written by faculty who are familiar with the applicant's work and can make an assessment of the potential for success in graduate school. The graduate program has grown to an enrollment of about 110, with 15 to 20 students arriving each year. All students admitted to graduate studies in Physics and Astronomy at Rice enter the PhD program directly (there is no terminal master's). For the PhD degree, students must complete at least eight approved graduate courses, demonstrate their ability to engage in advanced research, and pass an oral PhD candidacy examination. There is no foreign language requirement, and no comprehensive written qualifying exam on coursework. Research facilities and thesis supervision are available for PhD students in Atomic, Molecular and Optical Physics, Biophysics, Condensed Matter Physics, Astrophysics of Star and Planet Formation, Relativistic Astrophysics and Cosmology, Nuclear and Particle Physics, and Space Plasma and Solar Physics. The department is located in Houston, Texas. Note: The Rice University Smalley-Curl Institute Applied Physics Graduate Program is a separate PhD program with its own December 31, 2026 deadline (11:59 p.m. ET), application fee waived for all applicants, GRE scores not currently required but optional (average admitted Applied Physics students score V156 / Q164 and above), and Physics Subject recommended but not required. This entry is Physics and Astronomy, NOT Applied Physics.",
        "requirements": "<ul><li>Bachelor's degree in physics or related quantitative field</li><li>GRE General: neither required nor made use of</li><li>GRE Physics Subject: neither required nor made use of</li><li>TOEFL iBT / IELTS required for non-native English speakers</li><li>ETS institution code 4822 (Rice)</li><li>TOEFL/IELTS may be waived for degrees from English-official-language universities</li><li>International students must provide proof of financial support</li><li>Rice Graduate and Postdoctoral Studies online application (opens September 1, 2026)</li><li>Three letters of recommendation</li><li>Research statement</li><li>Transcripts</li><li>CV/Resume</li><li>**Deadline December 15, 2026, 11:59 p.m. EST**</li><li>Late applications may be considered until April 1, 2027 but less competitive</li><li>Fall admission only (no spring)</li><li>At least 8 approved graduate courses</li><li>Oral PhD candidacy examination</li><li>No comprehensive written qualifying exam</li><li>No foreign language requirement</li><li>All students enter PhD directly (no terminal MS)</li><li>Separate from Rice Applied Physics Smalley-Curl Institute (Dec 31)</li><li>On-campus residential (Houston, TX)</li></ul>",
        "research": "<ul><li>Atomic, Molecular and Optical Physics</li><li>Biological physics / biophysics</li><li>Experimental condensed matter physics and materials physics</li><li>Theoretical condensed matter physics</li><li>Astrophysics of star and planet formation</li><li>Relativistic astrophysics and cosmology</li><li>Nuclear and particle physics</li><li>Space plasma and solar physics</li><li>Interdisciplinary research with Rice Smalley-Curl Institute, Baker Institute, and other centers (note: Applied Physics is separate PhD)</li></ul>",
        "source": '<a href="https://physics.rice.edu/how-apply" target="_blank">Rice Physics How to Apply (Fall 2027 deadline December 15, 2026 11:59 EST; application system opens Sept 1, 2026; late apps until April 1, 2027 less competitive; neither requires nor makes use of GRE general or subject; absence does not affect; 3 LOR)</a> | <a href="https://physics.rice.edu/graduate-program-overview" target="_blank">Rice Physics Graduate Program Overview (~110 grad students; 15-20 entering/year; all enter PhD directly no terminal MS; 8 approved grad courses; oral PhD candidacy; no foreign language; no comprehensive written qual; research areas AMO/Biophysics/Condensed Matter/Stellar Astrophysics/Relativistic Astrophysics/Nuclear Particle/Space Plasma)</a> | <a href="https://appliedphysics.rice.edu/prospective-students/application/apply" target="_blank">Rice Applied Physics Apply (SEPARATE; December 31 deadline; fee waived for all applicants; GRE not required but optional; average admitted V156/Q164+; Physics Subject recommended but not required; no late applications accepted; fall only)</a> | <a href="https://graduate.rice.edu/admissions/application-faq" target="_blank">Rice Graduate and Postdoctoral Studies Application FAQ (Rice generally not requiring GRE for Fall 2026; individual programs recommend/strongly recommend/require; Physics falls under no requirement/made use of)</a>',
    },
    "vanderbilt-physics-phd": {
        "school": "Vanderbilt University, College of Arts and Science, Department of Physics and Astronomy",
        "en": "PhD in Physics",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Typically 5-6 years; coursework; preliminary and qualifying exams; candidacy; dissertation; on-campus (Nashville, TN); Fall admission only; initial offers by March 31, response due April 15",
        "ddl": "Fall 2027: **Deadline December 1, 2026**. Applications open August 1, 2026. Initial Fall admission offers by March 31; response due April 15. Note: Vanderbilt Astrophysics PhD has separate December 7 deadline.",
        "lang": "TOEFL iBT / IELTS / Duolingo required for non-native English speakers per Vanderbilt Graduate School language proficiency waiver policy. ETS institution code 1871 (no department code needed; if ETS requires department code, select any listed). Scores valid within 5 years to month of intended first term.",
        "test_cls": "GRE GENERAL NOT REQUIRED; GRE PHYSICS SUBJECT NOT REQUIRED (Vanderbilt Physics: 'Do not submit GRE scores (General nor Subject). They are not required and will not be considered.' Graduate School program table lists Physics PhD as GRE Exempt.)",
        "tui": "100% financial aid for PhD students through RA/TA/fellowship: tuition + stipend + health insurance. Initial offers by March 31; response due April 15.",
        "overview": "The Vanderbilt University Department of Physics and Astronomy, within the College of Arts and Science and the Vanderbilt Graduate School, offers the Doctor of Philosophy (PhD) in Physics. Applications for Fall 2027 open on August 1, 2026 and must be submitted through the Graduate School Application Portal. The application deadline is December 1, 2026. CRITICAL POLICY: GRE scores are not required. Do not submit GRE scores (General nor Subject). They are not required and will not be considered. The Graduate School application requirements by program table lists Physics PhD as GRE Exempt with Fall application date December 1. Strong applications to the physics PhD program include: the student's academic record from prior institutions, a statement of purpose that details the student's interests in graduate school and beyond, and three or more reference letters that provide insight into an applicant's prior experience, motivation for graduate school, and aptitude for research. Applicants do not need to submit an official transcript unless admitted to the program; they should load their unofficial transcript directly into their application. If offered admission, they will need to send official transcripts showing the degree earned; they may have to have their final transcript sent after they graduate as the transcript needs to show the degree conferred. The ETS institution code for Vanderbilt Graduate School is 1871; no department code is needed, and if ETS requires a department code, applicants may select any listed on ETS's site - regardless of department code entered, scores will come to the Graduate School as long as institution code 1871 is used. Scores are valid if earned within five years to the month of intended first term at Vanderbilt. Most programs release initial Fall admission offers by March 31 with a response due by April 15; the timing of admission offers varies by program, and programs may continue to extend offers after that date. The department is located in Nashville, Tennessee. Note: Vanderbilt Astrophysics PhD is a separate program with a December 7, 2026 deadline (per Graduate School program table) - this entry is Physics, NOT Astrophysics.",
        "requirements": "<ul><li>Bachelor's degree in physics or related quantitative field</li><li>GRE General: NOT required (do not submit; will not be considered)</li><li>GRE Physics Subject: NOT required (do not submit; will not be considered)</li><li>TOEFL iBT / IELTS / Duolingo required for non-native English speakers</li><li>ETS institution code 1871 (no department code needed)</li><li>Scores valid within 5 years to month of intended first term</li><li>Vanderbilt Graduate School online application (opens August 1, 2026)</li><li>Statement of Purpose (1000-2000 words) describing motivations and research interests</li><li>Three or more letters of recommendation</li><li>Unofficial transcripts (upload directly to application)</li><li>Official transcripts required only upon admission (must show degree conferred)</li><li>CV/Resume</li><li>**Deadline December 1, 2026**</li><li>Fall admission only</li><li>Initial offers by March 31; response due April 15</li><li>100% of PhD students receive financial aid</li><li>Separate from Vanderbilt Astrophysics PhD (Dec 7, 2026)</li><li>On-campus residential (Nashville, TN)</li></ul>",
        "research": "<ul><li>Experimental condensed matter physics</li><li>Theoretical condensed matter physics</li><li>High energy physics / particle physics</li><li>Astrophysics (separate Astrophysics PhD program)</li><li>Biological physics / medical physics</li><li>Optical physics and quantum optics</li><li>Plasma physics</li><li>Quantum information science</li><li>Interdisciplinary research with Vanderbilt Institute of Nanoscale Science and Engineering, Vanderbilt Institute for Integrative Biosystems Research and Education, and other centers</li></ul>",
        "source": '<a href="https://as.vanderbilt.edu/physics-astronomy/phd-physics-admissions/" target="_blank">Vanderbilt Physics PhD Admissions (Fall 2027 opens Aug 1, 2026; deadline December 1, 2026; GRE scores not required; do not submit GRE scores General nor Subject; they are not required and will not be considered; 3+ LOR; SOP; unofficial transcripts; contact Don Pickert Program Specialist)</a> | <a href="https://gradschool.vanderbilt.edu/application-requirements/" target="_blank">Vanderbilt Graduate School Application Requirements (Fall application deadlines range Dec 1 to Jan 15 by department; initial offers by March 31 with response due April 15; ETS institution code 1871 no dept code needed; scores valid 5 years)</a> | <a href="https://gradschool.vanderbilt.edu/admissions/apply/application-requirements-by-program/" target="_blank">Vanderbilt Application Requirements by Program (Physics PhD: Arts & Science, GRE Exempt, Fall Dec 1; Astrophysics PhD: Arts & Science, GRE Exempt, Fall Dec 7 - SEPARATE)</a> | <a href="https://as.vanderbilt.edu/physics-astronomy/graduate/phd-astrophysics/" target="_blank">Vanderbilt Astrophysics PhD (SEPARATE; Fall 2027 opens Aug 1; deadline December 7, 2026; GRE not required; SOP 1000-2000 words; 3+ LOR; unofficial transcripts)</a>',
    },
    "brown-physics-phd": {
        "school": "Brown University, Department of Physics",
        "en": "PhD in Physics (two tracks: Physics and Astrophysics - must select one at application; separate from Brown Applied Math Division PhD)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Typically 5-6 years; core courses (Physics core PHYS 2030, 2040, 2050, 2060; Astrophysics core PHYS 2010, 2270, 2280); qualifying exams; teaching requirement; candidacy; dissertation; on-campus (Providence, RI); Fall admission only",
        "ddl": "Fall 2027: **Deadline December 15, 2026** (11:59 p.m. Eastern). Application opens September 8, 2026. Note: Brown Applied Math Division PhD has separate December 9, 2026 deadline and requires General GRE.",
        "lang": "TOEFL iBT / IELTS required for non-native English speakers. Recommended minimum TOEFL 90 iBT (577 paper); recommended minimum IELTS overall band 7.0. Brown ETS institution code 3094; Physics code for TOEFL reporting: 76. Self-reported TOEFL accepted for initial review; official required upon admission.",
        "test_cls": "PHYSICS TRACK: GRE PHYSICS SUBJECT REQUIRED (waived if applicant already holds master's degree in physics or related field); GENERAL GRE OPTIONAL. ASTROPHYSICS TRACK: SUBJECT NOT CONSIDERED; GENERAL OPTIONAL (Brown Physics: 'For the Physics track, GRE subject scores are required. For the Astrophysics track, the GRE subject will not be considered. The general GRE is optional for both tracks. The GRE Subject Test score requirement is waived for applicants who have a master's degree in physics or a related field.')",
        "tui": "Multi-year fully-funded through RA/TA/fellowship: tuition + stipend + health insurance. Note: Brown also offers tuition-based ScM separate from funded PhD; ScM students cannot automatically transition to PhD.",
        "overview": "The Brown University Department of Physics, within the Brown Graduate School, offers the Doctor of Philosophy (PhD) in Physics. The Physics and Astrophysics PhD program is open annually from early September to a deadline of December 15. The Fall 2027 application opens on September 8, 2026 with a deadline of December 15, 2026 at 11:59 p.m. Eastern. CRITICAL POLICY: There are two separate tracks within the PhD program: Physics and Astrophysics. Students must select one of the two tracks when completing their application. GRE requirements differ for applications to the Physics and Astrophysics tracks. For the Physics track, GRE subject scores are required. For the Astrophysics track, the GRE subject will not be considered. The general GRE is optional for both tracks. The GRE Subject Test score requirement is waived for applicants who have a master's degree in physics or a related field. Students are admitted to the specific track selected on their application and cannot switch between them once enrolled in the program. Therefore, only students with an exclusive interest in astrophysics (experimental and/or theoretical) should apply to the Astrophysics track. Students who might want to pursue study in either astrophysics or another area of physics should apply to the Physics track. Prospective students are encouraged to contact specific faculty members to determine whether their current research projects align more closely with the Physics or Astrophysics tracks. Applicants are expected to have a strong background in physics or closely related subjects at the undergraduate level. All applications are evaluated holistically to assess the applicant's preparation and potential for graduate coursework and independent research, which can be demonstrated in multiple ways. Three recommendation letters from faculty or others acquainted with the applicant's academic and/or research qualifications are required. For English language, the recommended minimum TOEFL score for admission consideration is 90 for the internet-based test (577 on the paper-based test). For IELTS, the recommended minimum overall band score is 7. Brown University requires official scores to be sent; applicants may self-report TOEFL scores and upload copies of score reports into the application, but must also have official scores sent to the Graduate School. Brown ETS institution code is 3094; Physics code for TOEFL reporting is 76. Note: The Brown Applied Math Division is a separate PhD program with a December 9, 2026 deadline and requires General GRE (Subject highly recommended) - this entry is Physics, NOT Applied Math. The department also offers a tuition-based ScM (Master of Science) program; students admitted to the Master's program cannot automatically transition to the PhD.",
        "requirements": "<ul><li>Bachelor's degree in physics or closely related subject</li><li>Physics track: GRE Physics Subject REQUIRED (waived if applicant already holds master's degree in physics or related field)</li><li>Astrophysics track: GRE Physics Subject NOT considered</li><li>Both tracks: GRE General optional</li><li>TOEFL iBT recommended minimum 90 (577 paper-based)</li><li>IELTS recommended minimum overall band 7.0</li><li>Self-reported TOEFL accepted for initial review; official required upon admission</li><li>Brown ETS institution code 3094; Physics code for TOEFL reporting: 76</li><li>Brown Graduate School online application (opens September 8, 2026)</li><li>Three letters of recommendation</li><li>CV/Resume</li><li>Statement of Purpose</li><li>Textbook/course list (undergraduate and graduate courses, textbooks used)</li><li>Unofficial transcripts</li><li>**Deadline December 15, 2026** (11:59 p.m. Eastern)</li><li>Fall admission only</li><li>Two tracks: Physics and Astrophysics - must select one at application; cannot switch once enrolled</li><li>Tuition-based ScM program separate from funded PhD; ScM students cannot auto-transition to PhD</li><li>Separate from Brown Applied Math Division PhD (Dec 9, General required, Subject highly recommended)</li><li>On-campus residential (Providence, RI)</li></ul>",
        "research": "<ul><li>Experimental condensed matter physics and soft matter</li><li>Theoretical condensed matter physics</li><li>High energy physics / particle physics</li><li>Astrophysics (separate Astrophysics track within Physics Dept)</li><li>Biological physics / biophysics</li><li>Atomic, molecular, and optical physics</li><li>Quantum information science</li><li>Physics education research</li><li>Interdisciplinary research with Brown Center for Quantum Information, Brown Center for Astrophysics, and other institutes</li></ul>",
        "source": '<a href="https://physics.brown.edu/academics/graduate/how-apply" target="_blank">Brown Physics How to Apply (applications from early Sept to Dec 15; two tracks Physics and Astrophysics; Physics track requires GRE subject; Astrophysics track does not consider subject; general optional both tracks; subject waived if master\'s in physics; cannot switch tracks once enrolled; ScM tuition-based separate)</a> | <a href="https://physics.brown.edu/academics/graduate/how-apply/testing-requirements" target="_blank">Brown Physics Testing Requirements (Physics Subject GRE required for PhD; General optional; subject waived if master\'s in physics or related; recommended TOEFL 90 iBT / 577 paper; IELTS 7.0; Brown ETS 3094; Physics TOEFL code 76; self-reported scores accepted for initial review; official required upon admission)</a> | <a href="https://graduateprograms.brown.edu/graduate-program/physics-phd" target="_blank">Brown Graduate Programs: Physics PhD (application requirements; GRE Subject Required Physics track only; General optional; TOEFL/IELTS required; resume/CV required; textbook list required; strong undergraduate physics background expected)</a> | <a href="https://apply.graduateschool.brown.edu/portal/program_explorer" target="_blank">Brown Graduate School Program Explorer (Physics Doctoral opens 09/08/2026; deadline 12/15/2026; Mathematics Doctoral 01/01/2027; Chemistry/CS Doctoral 12/15/2026)</a>',
    },
    "duke-physics-phd": {
        "school": "Duke University, Trinity College of Arts and Sciences, Department of Physics",
        "en": "PhD in Physics (~116 graduate students / 45 faculty; 100% financial aid; highly selective from 300+ applicants per year)",
        "deg": "Doctor of Philosophy (PhD)",
        "stem_label": "STEM-designated (Physics / CIP 40.0801)",
        "dur": "Typically 5-6 years; core courses in mathematical methods, classical mechanics, quantum mechanics, statistical mechanics, electrodynamics; approved electives; preliminary examination (including proposed PhD thesis research plan); dissertation; on-campus (Durham, NC); Fall admission only; students decide research group by end of fourth semester",
        "ddl": "Fall 2027: **Deadline December 1, 2026, 11:59:59 p.m. EST**. All application materials (including LORs) should be received by this date for full consideration. Duke Graduate School deadline table confirms Physics PhD 12/01/2026.",
        "lang": "TOEFL iBT minimum 90 (internet-based); IELTS minimum overall 7.0. Duolingo English Test also accepted per Graduate School. ETS institution code 5116. Test waiver may apply for some applicants per Graduate School policy.",
        "test_cls": "GRE GENERAL OPTIONAL; GRE PHYSICS SUBJECT OPTIONAL (Duke Physics: 'Submission of general and/or Physics subject GRE scores is optional. Applicants who do not submit GRE scores will receive full consideration. Nonetheless, the submission of GRE scores may be advantageous in certain circumstances. While there are no acceptable minimum scores, matriculating students average 159 verbal, about 166 quantitative, and 3.5 in writing. The GRE Physics is recommended but not required; matriculating students typically receive a score of 700 or above. Admission distribution, not minimum threshold.')",
        "tui": "100% of PhD students receive financial aid through RA/TA/fellowship: tuition + stipend + health insurance. Highly selective: ~300+ applicants/year, admits only most exceptional candidates.",
        "overview": "The Duke University Department of Physics, within the Trinity College of Arts and Sciences and the Duke Graduate School, offers the Doctor of Philosophy (PhD) in Physics. For full consideration, all application materials (including letters of recommendation) should be received by December 1, 2026, 11:59:59 p.m. Eastern Standard Time. Duke Graduate School deadline table confirms Physics PhD deadline of 12/01/2026 for Fall 2027. CRITICAL POLICY: Submission of general and/or Physics subject GRE scores is optional. Applicants who do not submit GRE scores will receive full consideration. Nonetheless, the submission of GRE scores may be advantageous in certain circumstances by providing additional information that is not conveyed by other application materials such as transcripts and letters. There are no acceptable minimum scores; however, matriculating students average 159 in verbal, about 166 in quantitative, and 3.5 in writing. The GRE Physics is recommended but not required; matriculating students typically receive a score of 700 or above. These are admission distribution figures, not minimum thresholds. For non-native English speakers, the minimum acceptable TOEFL score is 90 (internet-based test), or a minimum IELTS score of 7.0. The department faculty have 45 members working with ~116 graduate students. Admissions decisions are made by the Graduate Admissions Committee (GAC) after reviewing the entire application package which includes: curriculum vitae, academic performance (official transcript), research experience, three or more letters of recommendation, and a statement of purpose describing research interests. Admission to Physics PhD at Duke is based on a number of factors including recommendation letters, personal statement, research experience, course grades (especially those in physics courses), overall quality of the applicant's undergraduate record, overlap of student research interests with Duke research areas, and TOEFL scores (where applicable). The department is highly competitive: typically admit only the most exceptional candidates from a pool of more than 300 applicants from around the world each year. Students research can start early; students usually have until the end of the fourth semester to decide on research groups. Collaborations with other departments are possible; advisors could be outside the department (if doing Physics). Degree requirements per Graduate School bulletin: graduate coursework in core subject areas (mathematical methods, classical mechanics, quantum mechanics, statistical mechanics, and electrodynamics) as well as approved electives; preparing for and passing the doctoral preliminary examination (including a proposed PhD thesis research plan); and completion of a doctoral dissertation under the supervision of a faculty advisor. The department is located in Durham, North Carolina. Fall admission only.",
        "requirements": "<ul><li>Bachelor's degree in physics or related quantitative field</li><li>GRE General: optional (no minimum; matriculating average V159/Q166/AW3.5 - admission distribution, not minimum threshold)</li><li>GRE Physics Subject: optional (recommended but not required; matriculating typically 700+ - admission distribution, not minimum threshold)</li><li>TOEFL iBT minimum 90 (internet-based)</li><li>IELTS minimum overall 7.0</li><li>Duolingo English Test also accepted per Graduate School</li><li>ETS institution code 5116</li><li>Test waiver may apply for some applicants per Graduate School policy</li><li>Duke Graduate School online application</li><li>Statement of Purpose (describing research interests)</li><li>Three or more letters of recommendation</li><li>Curriculum Vitae / Resume</li><li>Official transcript (required with application)</li><li>Writing sample: none required</li><li>Undergraduate GPA calculated on 4.0 scale required</li><li>**Deadline December 1, 2026, 11:59:59 p.m. EST**</li><li>All materials (including LORs) received by deadline for full consideration</li><li>Fall admission only</li><li>Core courses: mathematical methods, classical mechanics, quantum mechanics, statistical mechanics, electrodynamics + approved electives</li><li>Doctoral preliminary examination (including proposed PhD thesis research plan)</li><li>Students decide research group by end of fourth semester</li><li>100% of PhD students receive financial aid</li><li>~300+ applicants/year; admits only most exceptional candidates</li><li>On-campus residential (Durham, NC)</li></ul>",
        "research": "<ul><li>Experimental condensed matter physics and materials physics</li><li>Theoretical condensed matter physics</li><li>High energy physics / particle physics</li><li>Astrophysics and cosmology</li><li>Biological physics / biophysics (interdisciplinary with Duke Medical Center)</li><li>Atomic, molecular, and optical physics</li><li>Quantum information science</li><li>Photonics and applied physics</li><li>Interdisciplinary research with Duke Institute for Brain Sciences, Duke Institute for Environmental Policy, and other centers</li></ul>",
        "source": '<a href="https://physics.duke.edu/graduate/prospective-students/admissions" target="_blank">Duke Physics Admissions (holistic review; GAC reviews CV, transcript, research experience, 3+ LOR, SOP; General and/or Physics Subject optional; no penalty for not submitting; submitted scores may be advantageous; contact DGS)</a> | <a href="https://gradschool.duke.edu/academics/programs-degrees/physics/" target="_blank">Duke Graduate School: Physics PhD (45 faculty; 90 students; 100% financial aid; Fall admission; Dec 1 deadline; GRE General Optional; GRE Subject Physics Optional; TOEFL/IELTS/Duolingo required; 3 LOR; SOP; CV; transcripts; no writing sample; undergrad GPA on 4.0)</a> | <a href="https://physics.duke.edu/graduate/prospective-students/admissions/process" target="_blank">Duke Physics Admissions Process (criteria: LOR, personal statement, research experience, course grades, undergrad record, research overlap, TOEFL; GRE optional; no minimum scores; matriculating average V159/Q166/AW3.5; Physics Subject 700+ admission distribution not minimum; TOEFL 90 / IELTS 7.0; Dec 1 deadline)</a> | <a href="https://gradschool.duke.edu/admissions/application-deadlines/" target="_blank">Duke Graduate School Application Deadlines (all dates 11:59:59 p.m. EST; Physics PhD 12/01/2026; CS PhD 12/15/2026; some programs continue accepting after deadline if spaces available)</a> | <a href="https://graduateschool.bulletins.duke.edu/programs/G-PHYS-PHD/requirements-IkDU1" target="_blank">Duke Graduate School Bulletin: G-PHYS-PHD Physics PhD (requirements: core courses in math methods/classical mechanics/QM/stat mech/electrodynamics + approved electives; preliminary examination including proposed PhD thesis research plan; dissertation under faculty advisor)</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)}")
