-
Notifications
You must be signed in to change notification settings - Fork 120
feat: steering to avoid chain breaks and clashes #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
71 commits
Select commit
Hold shift + click to select a range
3b3dd46
feat: add TODO for fk steering implementation in heun_denoiser
ludwigwinkler 3069e93
Merge branch 'main' into luwinkler/fk_steering
ludwigwinkler 6829f31
gitignore test outputs and test case for steering
ludwigwinkler ec98369
Merge branch 'luwinkler/fk_steering' of os.github.com:microsoft/bioem…
ludwigwinkler f61a0aa
first prototype
ludwigwinkler 80a1de2
feat: implement Kabsch alignment and enhance steering functionality w…
ludwigwinkler 046aeaf
feat: add wandb to .gitignore to exclude Weights and Biases files
ludwigwinkler bf583db
Refactor steering module and add new steering run script
ludwigwinkler 7cfaa08
Add BioEMU development rules and enhance load_md script
ludwigwinkler c8a737b
Enhance BioEMU documentation and introduce new analytical diffusion m…
ludwigwinkler 135b6ef
Update .gitignore to exclude fasta files in notebooks directory
aea00cd
Update .gitignore to exclude output files from notebooks directory
af1bcc0
Refactor tqdm imports in analytical_diffusion, run_steering_compariso…
0d3dd81
Remove .cursor/ from tracking and add to .gitignore
206860e
Delete .cursor/rules directory
ludwigwinkler f0fee56
Update .gitignore to exclude all files in .cursor directory
fc5093d
Merge branch 'luwinkler/fk_steering' of github.com:microsoft/bioemu i…
4cc3af2
Enhance steering functionality and introduce new potentials
5452976
first workin prototype of fast_steering
baeb075
Enhance steering capabilities and update documentation
40ae947
Refine steering documentation and enhance configuration handling
a42c5da
Update README to refine steering section and enhance CLI usage instru…
691dea8
Update README to include Python API example for steering and remove H…
516046d
Update .gitignore to exclude documentation files
917c47a
Refactor steering configuration and enhance disulfide bridge potential
4f92d08
Add guidance steering capabilities and update experiment scripts
a0bdd14
Enhance guidance steering implementation and update experiment config…
916f1ba
Enhance guidance steering comparison and update configurations
eb9fec9
Modify final resampling step in denoiser.py
YuuuXie a12ffdd
fix x0 type
YuuuXie 389542e
Add physicality steering comparison notebook and update configurations
467db4a
Merge branch 'luwinkler/cli_steering' of github.com:microsoft/bioemu …
5bfe137
Update README.md
ludwigwinkler 3072756
Update README.md
ludwigwinkler 9e6c71b
Update README.md
ludwigwinkler 65f44a0
refs for readme on steering and smc
4c09554
Merge branch 'luwinkler/cli_steering' of github.com:microsoft/bioemu …
b379b2e
Update notebooks/README_hydra_run.md
ludwigwinkler ac46972
some renaming files and typos
da161c3
Merge branch 'luwinkler/cli_steering' of github.com:microsoft/bioemu …
7aaa635
Remove unused guidance images: deleted `guidance_steering_comparison.…
9a2a405
Remove profiler module: deleted `src/bioemu/profiler.py` as it is no …
25b5bfd
Remove unused steering scratch pad: deleted `src/steering_scratch_pad…
2c97e05
Remove unused denoiser configuration: deleted `src/bioemu/config/deno…
da475bf
Remove unused guidance steering configuration: deleted `src/bioemu/co…
16c2da8
Merge branch 'main' into luwinkler/cli_steering
ludwigwinkler 741d69d
Update .gitignore to exclude additional files, enhance pyproject.toml…
e28c475
simplified steering logic and first prototype for integrated sampling…
4d6455e
cleaned up notebooks and configs
60e92ae
Refactor steering configuration and update README for clarity. Remove…
46161fd
Remove commented TODO regarding embedding file copying in get_embeds.…
480b405
fix formatting
9252860
Fix save_pdb_and_xtc function to use the first element of pos_angstro…
885b4f2
fixing small deviations in the code to reduce mental load of the revi…
479d84b
fixing diverging code
0ac2b42
Update steering parameters in README.md to reflect new default values…
3312cd4
Refactor steering parameters and update configuration for consistency…
09f0850
Add disulfide bridge steering potential and example scripts for compa…
7b34735
Merge branch 'main' into luwinkler/cli_steering
ludwigwinkler cc20170
Add type hints to log_physicality and potential_loss_fn functions for…
6095451
Refactor logging in log_physicality function and add logger initializ…
1923313
ReadMe update and typo fix
9910f82
reverted back to no return sample() function
1c48ebf
Remove sample result validation from steering tests for cleaner output
e2360dd
Update steering section in README to clarify the use of steering part…
5aba79a
black formatter pre-commit hook
99fe49b
small ReadMe update
ccaa477
Add integration tests for CLI functionality in BioEMU
08967a0
Refactor disulfide bridge steering example to encapsulate main logic …
0e5523c
Refactor denoiser and steering potentials to streamline input paramet…
dd5d1f7
Merge branch 'main' into luwinkler/cli_steering
ludwigwinkler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| """Script to compare sampling with and without physicality steering.""" | ||
|
|
||
| import logging | ||
| from pathlib import Path | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
| import torch | ||
|
|
||
| from bioemu.sample import main as sample_main | ||
|
|
||
| logging.basicConfig(level=logging.INFO) | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def bridge_distances(pos: torch.Tensor, bridge_indices: list[tuple[int, int]]) -> torch.Tensor: | ||
| """Compute Ca-Ca distances for specified disulfide bridge indices. | ||
|
|
||
| Args: | ||
| pos (torch.Tensor): Tensor of shape (N, L, 3) | ||
| """ | ||
| import torch | ||
|
|
||
| distances = [] | ||
| for i, j in bridge_indices: | ||
| dist_ij = torch.norm(pos[:, i, :] - pos[:, j, :], dim=-1) # (N,) | ||
| distances.append(dist_ij) | ||
| return torch.stack(distances, dim=-1) # (N, num_bridges) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
| # https://www.uniprot.org/uniprotkb/P01542/entry#sequences | ||
| # TTCCPSIVARSNFNVCRLPGTPEALCATYTGCIIIPGATCPGDYAN | ||
| # PTM = [(3,40), (4,32), (16, 26)] | ||
| bridge_indices = [(2, 39), (3, 31), (15, 25)] # adjusted by -1 to be 0-indexed | ||
|
|
||
| """Sample 128 structures with and without physicality steering.""" | ||
|
|
||
| # Configuration | ||
| sequence = "TTCCPSIVARSNFNVCRLPGTPEALCATYTGCIIIPGATCPGDYAN" # Example sequence | ||
| num_samples = 128 | ||
| base_output_dir = Path("comparison_outputs_disulfide") | ||
|
|
||
| # Sample WITHOUT steering | ||
| logger.info("=" * 80) | ||
| logger.info("Sampling WITHOUT steering...") | ||
| logger.info("=" * 80) | ||
| output_dir_no_steering = base_output_dir / "no_steering" | ||
| sample_main( | ||
| sequence=sequence, | ||
| num_samples=num_samples, | ||
| output_dir=output_dir_no_steering, | ||
| batch_size_100=500, | ||
| denoiser_config="../src/bioemu/config/denoiser/stochastic_dpm.yaml", # Use stochastic DPM | ||
| steering_config=None, # No steering | ||
| ) | ||
| pos_unsteered = torch.from_numpy( | ||
| np.load(list(output_dir_no_steering.glob("batch_*.npz"))[0])["pos"] | ||
| ) | ||
|
|
||
| unsteered_bridge_distances = bridge_distances(pos_unsteered, bridge_indices) | ||
|
|
||
| # Sample WITH steering | ||
| logger.info("=" * 80) | ||
| logger.info("Sampling WITH physicality steering...") | ||
| logger.info("=" * 80) | ||
| output_dir_with_steering = base_output_dir / "with_steering" | ||
| sample_main( | ||
| sequence=sequence, | ||
| num_samples=num_samples, | ||
| output_dir=output_dir_with_steering, | ||
| denoiser_config="../src/bioemu/config/denoiser/stochastic_dpm.yaml", # Use stochastic DPM | ||
| steering_config="../src/bioemu/config/steering/disulfide_bridge_steering.yaml", # Use disulfide bridge steering | ||
| ) | ||
|
|
||
| pos_steered = torch.from_numpy( | ||
| np.load(list(output_dir_with_steering.glob("batch_*.npz"))[0])["pos"] | ||
| ) | ||
|
|
||
| steered_bridge_distances = bridge_distances( | ||
| pos_steered, bridge_indices | ||
| ) # pos_rot_steered in Angstrom | ||
| logger.info("=" * 80) | ||
| logger.info("Comparison complete!") | ||
| logger.info(f"Results without steering: {output_dir_no_steering}") | ||
| logger.info(f"Results with steering: {output_dir_with_steering}") | ||
| logger.info("=" * 80) | ||
|
|
||
| # Distances are in Angstrom | ||
| fig, ax = plt.subplots(1, 2, figsize=(16, 8)) | ||
| ax[0].hist( | ||
| unsteered_bridge_distances.numpy().flatten(), bins=50, alpha=0.5, label="No Steering" | ||
| ) | ||
| ax[0].hist( | ||
| steered_bridge_distances.numpy().flatten(), bins=50, alpha=0.5, label="With Steering" | ||
| ) | ||
| ax[0].legend() | ||
| ax[0].set_xlim(0, 5) | ||
| ax[0].set_xlabel("Cα-Cα Distance (nM)") | ||
| ax[0].grid() | ||
| ax[1].hist( | ||
| unsteered_bridge_distances.numpy().flatten(), bins=100, alpha=0.5, label="No Steering" | ||
| ) | ||
| ax[1].hist( | ||
| steered_bridge_distances.numpy().flatten(), bins=100, alpha=0.5, label="With Steering" | ||
| ) | ||
| ax[1].legend() | ||
| ax[1].set_xlim(0.25, 1) | ||
| ax[1].set_xlabel("Cα-Cα Distance (nM)") | ||
| ax[1].grid() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| """Script to compare sampling with and without physicality steering.""" | ||
|
|
||
| import logging | ||
| from pathlib import Path | ||
|
|
||
| from bioemu.sample import main as sample_main | ||
|
|
||
| logging.basicConfig(level=logging.INFO) | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def main(): | ||
| """Sample 128 structures with and without physicality steering.""" | ||
|
|
||
| # Configuration | ||
| sequence = "MTEIAQKLKESNEPILYLAERYGFESQQTLTRTFKNYFDVPPHKYRMTNMQGESRFLHPL" # Example sequence | ||
| num_samples = 128 | ||
| base_output_dir = Path("comparison_outputs") | ||
|
|
||
| # Sample WITHOUT steering | ||
| logger.info("=" * 80) | ||
| logger.info("Sampling WITHOUT steering...") | ||
| logger.info("=" * 80) | ||
| output_dir_no_steering = base_output_dir / "no_steering" | ||
| sample_main( | ||
| sequence=sequence, | ||
| num_samples=num_samples, | ||
| output_dir=output_dir_no_steering, | ||
| denoiser_config="../src/bioemu/config/denoiser/stochastic_dpm.yaml", # Use stochastic DPM | ||
| steering_config=None, # No steering | ||
| ) | ||
|
|
||
| # Sample WITH steering | ||
| logger.info("=" * 80) | ||
| logger.info("Sampling WITH physicality steering...") | ||
| logger.info("=" * 80) | ||
| output_dir_with_steering = base_output_dir / "with_steering" | ||
| sample_main( | ||
| sequence=sequence, | ||
| num_samples=num_samples, | ||
| output_dir=output_dir_with_steering, | ||
| denoiser_config="../src/bioemu/config/denoiser/stochastic_dpm.yaml", # Use stochastic DPM | ||
| steering_config="../src/bioemu/config/steering/physical_steering.yaml", # Use physicality steering | ||
| ) | ||
|
|
||
| logger.info("=" * 80) | ||
| logger.info("Comparison complete!") | ||
| logger.info(f"Results without steering: {output_dir_no_steering}") | ||
| logger.info(f"Results with steering: {output_dir_with_steering}") | ||
| logger.info("=" * 80) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.