Skip to content

Add production run python scripts#26

Open
stevenluo22 wants to merge 28 commits into
cabb99:masterfrom
stevenluo22:master
Open

Add production run python scripts#26
stevenluo22 wants to merge 28 commits into
cabb99:masterfrom
stevenluo22:master

Conversation

@stevenluo22

@stevenluo22 stevenluo22 commented Nov 18, 2024

Copy link
Copy Markdown
Contributor

Add production run python scripts as well as other ancillary example scripts

Summary by Sourcery

Add new Python scripts for production runs and protein-DNA analysis, enhancing the simulation capabilities and force calculations in the DNA analysis scripts.

New Features:

  • Introduce new Python scripts for running production simulations and analyzing protein-DNA interactions.

Enhancements:

  • Enhance DNA analysis scripts by adding new force calculations and simulation setup.

@sourcery-ai

sourcery-ai Bot commented Nov 18, 2024

Copy link
Copy Markdown

Reviewer's Guide by Sourcery

This PR adds production run Python scripts and analysis tools for DNA-protein simulations. The main changes include adding a new production run script with comprehensive simulation setup, modifying the DNA analysis script to remove protein-related code, and adding new analysis tools for computing DNA twist angles.

Sequence diagram for DNA-Protein Simulation Setup

sequenceDiagram
    participant User
    participant Script
    participant OpenMM
    participant DNA
    participant Protein
    participant ForceField
    participant Simulation
    User->>Script: Run simulation script
    Script->>OpenMM: Initialize platform
    Script->>DNA: Create DNA object
    Script->>Protein: Create Protein object
    Script->>ForceField: Create force field
    ForceField->>Simulation: Create system
    Script->>Simulation: Initialize simulation
    Simulation->>Simulation: Add forces
    Simulation->>Simulation: Run simulation steps
    Simulation->>User: Output results
Loading

Sequence diagram for DNA Twist Angle Computation

sequenceDiagram
    participant User
    participant Script
    participant DNA
    participant ComputeTwist
    User->>Script: Run twist computation script
    Script->>DNA: Load DNA structure
    Script->>ComputeTwist: Compute twist angles
    ComputeTwist->>Script: Return twist angles
    Script->>User: Output twist angles
Loading

Class diagram for DNA and Protein Simulation

classDiagram
    class DNA {
        +fromCoarsePDB(file: str)
        +periodic: bool
    }
    class Protein {
        +fromCoarsePDB(file: str, sequence: str)
        +setup_virtual_sites(system)
        +periodic: bool
    }
    class ForceField {
        +createSystem(topology)
    }
    class Simulation {
        +context: Context
        +reporters: list
        +step(steps: int)
        +minimizeEnergy()
        +loadCheckpoint(file: str)
    }
    class Context {
        +setPositions(positions)
        +setVelocitiesToTemperature(temperature)
        +getState(getEnergy: bool, groups: int)
    }
    class Integrator {
        +setTemperature(temperature)
    }
    class Platform {
        +getPlatformByName(name: str)
        +setPropertyDefaultValue(property: str, value: str)
    }
    DNA --> ForceField
    Protein --> ForceField
    ForceField --> Simulation
    Simulation --> Context
    Simulation --> Integrator
    Simulation --> Platform
    Context --> Integrator
    Context --> Platform
Loading

File-Level Changes

Change Details Files
Added a new production run script for DNA-protein simulations
  • Implemented command-line argument parsing for simulation parameters
  • Added simulation platform and device configuration
  • Implemented checkpoint handling for simulation continuity
  • Added comprehensive force field setup for DNA-protein interactions
  • Implemented energy reporting and trajectory analysis
open3SPN2/scripts/protein_DNA_run.py
Modified DNA analysis script to focus on DNA-specific calculations
  • Removed protein-related code sections
  • Added DNA twist bias force calculations
  • Implemented extra bond force calculations
  • Updated force group assignments
examples/DNA_analysis.py
Added DNA twist computation utilities
  • Implemented vector manipulation functions
  • Added multiple methods for twist calculation
  • Implemented comparison functions between different twist calculation methods
  • Added test functionality for twist calculations
open3SPN2/compute_twist.py
Added analysis scripts for protein-DNA simulations
  • Implemented energy calculation and reporting
  • Added trajectory analysis capabilities
  • Added force field setup for analysis
  • Implemented platform-specific configurations
open3SPN2/scripts/protein_DNA_analysis.py
examples/protein_DNA_analysis.py
examples/DNA_analysis_PU1_AMHGo.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @stevenluo22 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider removing hardcoded paths (e.g. '/home/sl206/Programs/openawsem') and using environment variables or configuration files instead for better portability
  • There is significant code duplication between the analysis scripts - consider refactoring common functionality into shared utility modules
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

force = s.getForce(i)
force_name="CMMotionRemover"

#Add 3SPN2 forces

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider extracting force calculation logic into a shared ForceCalculator module

The force calculation logic is duplicated between this file and compute_twist.py. To reduce complexity and maintenance burden, consider extracting the common force calculations into a shared module:

# force_calculator.py
class ForceCalculator:
    @staticmethod
    def setup_3spn2_forces(dna, system):
        forces = {}
        for force_name in open3SPN2.forces:
            force = open3SPN2.forces[force_name](dna)
            if force_name in ['BasePair','CrossStacking']:
                force.addForce(system)
            else:
                system.addForce(force)
            forces[force_name] = force
        return forces

    @staticmethod 
    def setup_awsem_forces(protein, dna, system, frags_dir, fragment_file):
        forces = {}
        # Move existing AWSEM force setup here
        return forces

Then both files can use this shared logic:

# In analysis script
forces = {}
forces.update(ForceCalculator.setup_3spn2_forces(dna, s))
forces.update(ForceCalculator.setup_awsem_forces(protein, dna, s, args.AWSEM, args.fragment))

This maintains all functionality while reducing code duplication and making future maintenance easier.

@stevenluo22

Copy link
Copy Markdown
Contributor Author

Newest commits have segregated relatively duplicate amongst forces terms code into separate forces_setup.py so you don't need to change the forces terms code multiple times across multiple scripts. This removes potential future errors down the road where one script (say run script) had modified inclusion of forces terms and another script forgot to modify (say analysis script).

And also updated and cleaned the info.dat generation file in the analysis script. Ensure to modify or at least check the analysis script, the info.dat generation parts, if you edit or customize the forces_setup.py file from the original. The info.dat file is verified to have Total Energies be the same as the intended terms (not Q or Rg) as of latest revisions.

Add new line to output after Caution message.
cabb99 added a commit that referenced this pull request Jun 4, 2026
Brings in Steven Luo's production-run and analysis scripts. The overlapping
force-code changes are taken from PR #27 (the consolidated rework of the same
work); PR #26's multi-chain string classes are superseded there and will be
folded into a single generalized class during the follow-up refactor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant