Hanziwww / AlphaFold3-GUI

AFusion: AlphaFold 3 GUI & Toolkit with Visualization
https://alphafold3-gui.readthedocs.io
GNU General Public License v3.0
73 stars 4 forks source link

Does it support AF3 installed in Conda? #3

Closed WongLoong-user closed 12 hours ago

WongLoong-user commented 21 hours ago

First of all, I would like to sincerely thank you for your GUI, which has been a huge help to those of us who are not very familiar with running things through the command line. Since we deployed AF3 in an environment created with Conda, I would like to know whether it is possible to use your GUI as well. Additionally, if it is compatible with Conda, should it be installed in the same environment as AF3, or does it require a separate environment?

Can I replace the "# Build the Docker command" section in the "# Run AlphaFold 3" part with the commands needed to run it in a Conda environment?

Hanziwww commented 20 hours ago

Thank you for your kind words. I think Afusion can work with AF3 if installed in the same environment. However, the startup commands for AF3 might differ slightly, especially when it comes to using it within a Conda environment. Can you provide me with the startup commands for the Conda environment as a reference?

WongLoong-user commented 20 hours ago

Sure, here are the commands required to run it in the Conda environment named af3:

conda activate af3 cd /home/user/alphafold3 python run_alphafold.py \ --json_path=/home/user/fold_input.json \ --model_dir=/home/user/models \ --db_dir=/home/user/public_databases \ --output_dir=/home/user/output

This is the command I use for a simple run. The input format for other parameters should be the same as the Python command used in Docker.

Hanziwww commented 20 hours ago

Thank you for bringing this to my attention. I've prepared an example solution to adapt the afusion/app.py code for running AlphaFold 3 in a Conda environment instead of Docker.

Modifications to afusion/app.py:


Line 290:

with st.expander("Configure Execution Settings", expanded=True):
    # Paths for execution
    af_script_dir = st.text_input(
        "AlphaFold3 Directory",
        value="/home/user/alphafold3",
        help="Path to the AlphaFold3 directory containing run_alphafold.py."
    )
    af_input_path = st.text_input(
        "AF Input Path",
        value=os.path.expanduser("~/af_input"),
        help="Path to AlphaFold input directory."
    )
    af_output_path = st.text_input(
        "AF Output Path",
        value=os.path.expanduser("~/af_output"),
        help="Path to AlphaFold output directory."
    )
    model_parameters_dir = st.text_input(
        "Model Parameters Directory",
        value="/home/user/models",
        help="Path to model parameters directory."
    )
    databases_dir = st.text_input(
        "Databases Directory",
        value="/home/user/public_databases",
        help="Path to databases directory."
    )

    logger.debug(
        f"Execution settings: af_script_dir={af_script_dir}, af_input_path={af_input_path}, "
        f"af_output_path={af_output_path}, model_parameters_dir={model_parameters_dir}, "
        f"databases_dir={databases_dir}"
    )

Explanation:


Line 338:

# Run AlphaFold 3
if st.button("Run AlphaFold 3 Now ▶️"):
    # Build the Conda command
    conda_command = (
        f"python {af_script_dir}/run_alphafold.py "
        f"--json_path={af_input_path}/fold_input.json "
        f"--model_dir={model_parameters_dir} "
        f"--db_dir={databases_dir} "
        f"--output_dir={af_output_path} "
        f"{'--run_data_pipeline' if run_data_pipeline else ''} "
        f"{'--run_inference' if run_inference else ''} "
        f"{'--buckets ' + ','.join(map(str, bucket_sizes)) if bucket_sizes else ''}"
    )

    st.markdown("#### Conda Command:")
    st.code(conda_command, language="bash")
    logger.debug(f"Conda command: {conda_command}")

    st.markdown("#### Conda Command:")
    st.code(conda_command, language="bash")
    logger.debug(f"Conda command: {conda_command}")

Explanation:


Updating the Software:

After making these changes, please run the following command in your project directory to update the software:

pip install .

This will reinstall your package with the updated code.


Next Steps:

I plan to officially release a new version of the software soon that will fully support execution in a Conda environment. Your feedback is invaluable in ensuring the update meets user needs.

Could you please try out these modifications and let me know if they work for you? If you encounter any issues or have suggestions, I'd greatly appreciate your feedback.

Best regards, Han

WongLoong-user commented 20 hours ago

Thank you so much!! I'll get back to you after the test.

WongLoong-user commented 16 hours ago

I am sorry, it seems there was an issue with my execution. After replacing the code:

with st.expander("Configure Execution Settings", expanded=True):
    # Paths for execution
    af_script_dir = st.text_input("AlphaFold3 Directory", value="/home/user/alphafold3", help="Path to the AlphaFold3 directory containing run_alphafold.py.")
    af_input_path = st.text_input("AF Input Path", value=os.path.expanduser("~/af_input"), help="Path to AlphaFold input directory.")
    af_output_path = st.text_input("AF Output Path", value=os.path.expanduser("~/af_output"), help="Path to AlphaFold output directory.")
    model_parameters_dir = st.text_input("Model Parameters Directory", value="/home/user/models", help="Path to model parameters directory.")
    databases_dir = st.text_input("Databases Directory", value="/home/user/public_databases", help="Path to databases directory.")
    logger.debug(f"Execution settings: af_script_dir={af_script_dir}, af_input_path={af_input_path}, "
                 f"af_output_path={af_output_path}, model_parameters_dir={model_parameters_dir}, "
                 f"databases_dir={databases_dir}")

and

# Run AlphaFold 3
if st.button("Run AlphaFold 3 Now ▶️"):
    # Build the Conda command
    conda_command = (
        f"conda run af3 "
        f"python {af_script_dir}/run_alphafold.py "
        f"--json_path={af_input_path}/fold_input.json "
        f"--model_dir={model_parameters_dir} "
        f"--db_dir={databases_dir} "
        f"--output_dir={af_output_path} "
        f"{'--run_data_pipeline' if run_data_pipeline else ''} "
        f"{'--run_inference' if run_inference else ''} "
        f"{'--buckets ' + ','.join(map(str, bucket_sizes)) if bucket_sizes else ''}"
    )

    st.markdown("#### Conda Command:")
    st.code(conda_command, language="bash")
    logger.debug(f"Conda command: {conda_command}")

    # Run the command and display output in a box
    with st.spinner('AlphaFold 3 is running...'):
        output_placeholder = st.empty()
        output = run_alphafold(conda_command, placeholder=output_placeholder)

I ran pip install again, but the af_script_dir option does not appear in the displayed interface.

Hanziwww commented 16 hours ago

However, I can see the option.

1733217188378
2024-12-03 09:12:35.697 | DEBUG    | __main__:main:298 - Execution settings: af_script_dir=/home/user/alphafold3, af_input_path=/home/mars/af_input, af_output_path=/home/mars/af_output, model_parameters_dir=/home/user/models, databases_dir=/home/user/public_databases
2024-12-03 09:12:35.697 | INFO     | __main__:main:305 - Run data pipeline: True, Run inference: True
2024-12-03 09:12:35.698 | INFO     | __main__:main:334 - JSON file saved to /home/mars/af_input/fold_input.json

Make sure you ran pip install . in the project root dictionary.

WongLoong-user commented 13 hours ago

I'm so sorry, you were right. I can use it now. I made a silly mistake by mixing up the app.py in the root directory and the one in the afusion path. It's fixed now! By the way, does the app.py in the root directory serve any other purpose? Also, I created a separate environment to install your AlphaFold3-GUI, so I made slight modifications to the code. I add a command at the beginning of the generated conda_command to activate the environment where I installed AlphaFold3.

# Run AlphaFold 3
if st.button("Run AlphaFold 3 Now ▶️"):
    # Build the Conda command
    conda_command = (
        f"conda run -n af3 "
        f"python {af_script_dir}/run_alphafold.py "
        f"--json_path={af_input_path}/fold_input.json "
        f"--model_dir={model_parameters_dir} "
        f"--db_dir={databases_dir} "
        f"--output_dir={af_output_path} "
        f"{'--run_data_pipeline' if run_data_pipeline else ''} "
        f"{'--run_inference' if run_inference else ''} "
        f"{'--buckets ' + ','.join(map(str, bucket_sizes)) if bucket_sizes else ''}"
    )

Thanks again for your help!