Automating the process of data generation via ChimeraX

Dear Sir/Madam, I am an undergraduate student working on a project and I am trying to generate values for the solvent accessible surface area, mean molecular lipophilicity potential and mean surface electrostatic potential for a dataset involving protein 3D structures (in pdb format). We also plan to introduce point mutations via ChimeraX using the swapaa command and measure the same values for the mutated proteins. As such, we were wondering if there is a way to automate this process of generating the values for each protein, without having to manually do it. We tried to test out some code to see if it is possible to run a python file in ChimeraX. This was the code we wrote: import chimerax import csv import os from chimerax.core.commands import run run(session, "open" + r'C:\Users\anany\Downloads\Research\Test_PDB_Passenger\P35579_MYH9.pdb') run(session, "color red") run("surf") However, we received this error message: openC:\Users\anany\Downloads\Research\Test_PDB_Passenger\P35579_MYH9.pdb Traceback (most recent call last): File "C:\Users\anany\Downloads\Research\Test_PDB_Passenger\test_import.py", line 6, in <module> run(session, "open" + r'C:\Users\anany\Downloads\Research\Test_PDB_Passenger\P35579_MYH9.pdb') File "C:\Program Files\ChimeraX 1.8\bin\Lib\site-packages\chimerax\core\commands\run.py", line 49, in run results = command.run(text, log=log, return_json=return_json) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\ChimeraX 1.8\bin\Lib\site-packages\chimerax\core\commands\cli.py", line 3156, in run raise UserError(self._error) chimerax.core.errors.UserError: Unknown command: openC:\Users\anany\Downloads\Research\Test_PDB_Passenger\P35579_MYH9.pdb Error opening python file C:\Users\anany\Downloads\Research\Test_PDB_Passenger\test_import.py We would appreciate your kind assistance! Thank you!

Dear Mishra, I can't answer the python part, but wanted to comment on your scientific approach: The electrostatic potential and molecular lipophilicity potential are spatially varying quantities, and best understood by coloring the surface by the values for interactive, qualitative visual understanding. The important part is the spatial distribution and how it might affect interacting with other molecules. Compressing this spatial information down to a single mean value (overall average) is not useful, in my opinion. Obviously, if you mutate a positive charge to a neutral one or negative, the electrostatic potential will be less positive in the vicinity of that residue and the mean will decrease, and if you mutate a polar residue to a nonpolar residue, the molecular lipophilicity potential will be higher in the vicinity of that residue and the mean will increase. You don't need to calculate some mostly meaningless number to tell you that. Regards, Elaine ----- Elaine C. Meng, Ph.D. UCSF Chimera(X) team Resource for Biocomputing, Visualization, and Informatics Department of Pharmaceutical Chemistry University of California, San Francisco
On Mar 12, 2025, at 7:44 AM, mishra.ananya.163--- via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Dear Sir/Madam,
I am an undergraduate student working on a project and I am trying to generate values for the solvent accessible surface area, mean molecular lipophilicity potential and mean surface electrostatic potential for a dataset involving protein 3D structures (in pdb format). We also plan to introduce point mutations via ChimeraX using the swapaa command and measure the same values for the mutated proteins. As such, we were wondering if there is a way to automate this process of generating the values for each protein, without having to manually do it. We tried to test out some code to see if it is possible to run a python file in ChimeraX.
This was the code we wrote: import chimerax import csv import os from chimerax.core.commands import run run(session, "open" + r'C:\Users\anany\Downloads\Research\Test_PDB_Passenger\P35579_MYH9.pdb') run(session, "color red") run("surf")
However, we received this error message:
openC:\Users\anany\Downloads\Research\Test_PDB_Passenger\P35579_MYH9.pdb Traceback (most recent call last): File "C:\Users\anany\Downloads\Research\Test_PDB_Passenger\test_import.py", line 6, in <module> run(session, "open" + r'C:\Users\anany\Downloads\Research\Test_PDB_Passenger\P35579_MYH9.pdb') File "C:\Program Files\ChimeraX 1.8\bin\Lib\site-packages\chimerax\core\commands\run.py", line 49, in run results = command.run(text, log=log, return_json=return_json) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\ChimeraX 1.8\bin\Lib\site-packages\chimerax\core\commands\cli.py", line 3156, in run raise UserError(self._error) chimerax.core.errors.UserError: Unknown command: openC:\Users\anany\Downloads\Research\Test_PDB_Passenger\P35579_MYH9.pdb
Error opening python file C:\Users\anany\Downloads\Research\Test_PDB_Passenger\test_import.py
We would appreciate your kind assistance! Thank you! _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/

Hi Mishra, Your open command is "openC:\Users\..." with no space between the "open" and the file path and that is why you get the error. A clearer way to write this code is path = r'C:\Users\anany\Downloads\Research\Test_PDB_Passenger\P35579_MYH9.pdb' run(session, f"open {path}" instead of run(session, "open" + r'C:\Users\anany\Downloads\Research\Test_PDB_Passenger\P35579_MYH9.pdb') Tom
On Mar 12, 2025, at 7:44 AM, mishra.ananya.163--- via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Dear Sir/Madam,
I am an undergraduate student working on a project and I am trying to generate values for the solvent accessible surface area, mean molecular lipophilicity potential and mean surface electrostatic potential for a dataset involving protein 3D structures (in pdb format). We also plan to introduce point mutations via ChimeraX using the swapaa command and measure the same values for the mutated proteins. As such, we were wondering if there is a way to automate this process of generating the values for each protein, without having to manually do it. We tried to test out some code to see if it is possible to run a python file in ChimeraX.
This was the code we wrote: import chimerax import csv import os from chimerax.core.commands import run run(session, "open" + r'C:\Users\anany\Downloads\Research\Test_PDB_Passenger\P35579_MYH9.pdb') run(session, "color red") run("surf")
However, we received this error message:
openC:\Users\anany\Downloads\Research\Test_PDB_Passenger\P35579_MYH9.pdb Traceback (most recent call last): File "C:\Users\anany\Downloads\Research\Test_PDB_Passenger\test_import.py", line 6, in <module> run(session, "open" + r'C:\Users\anany\Downloads\Research\Test_PDB_Passenger\P35579_MYH9.pdb') File "C:\Program Files\ChimeraX 1.8\bin\Lib\site-packages\chimerax\core\commands\run.py", line 49, in run results = command.run(text, log=log, return_json=return_json) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\ChimeraX 1.8\bin\Lib\site-packages\chimerax\core\commands\cli.py", line 3156, in run raise UserError(self._error) chimerax.core.errors.UserError: Unknown command: openC:\Users\anany\Downloads\Research\Test_PDB_Passenger\P35579_MYH9.pdb
Error opening python file C:\Users\anany\Downloads\Research\Test_PDB_Passenger\test_import.py
We would appreciate your kind assistance! Thank you! _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/

Thank you so much for your help! We tried running the following code: # Function to calculate the properties for each PDB file def calculate_properties(pdb_file): try: # Open the PDB file in ChimeraX run(session, f"open {pdb_file}") # Calculate SASA (Solvent Accessible Surface Area) run(session, "surface") sasa_value = run(session, "measure sasa") # Calculate Mean MLP (Mean Molecular Lipophilicity Potential) mlp_value = run(session, "mlp") # Calculate Mean Electrostatic Potential electrostatic_value = run(session, "coulombic") # Close the model to free memory run("close all") return sasa_value, mlp_value, electrostatic_value except Exception as e: print(f"Error processing {pdb_file}: {e}") return None, None, None # Function to save results to a CSV file def save_results_to_csv(results, output_file): with open(output_file, mode='w', newline='') as file: writer = csv.writer(file) writer.writerow(["PDB File", "SASA", "MLP", "Electrostatic Potential"]) for result in results: writer.writerow(result) # List of PDB files (replace with your actual file paths) pdb_files = [ r'/Users/nikhita/Downloads/WT_EGFR.pdb', r'/Users/nikhita/Downloads/WT_MTOR.pdb' ] # List to store the results results = [] # Loop through the PDB files and calculate the properties for pdb_file in pdb_files: print(f"Processing {pdb_file}...") sasa_value, mlp_value, electrostatic_value = calculate_properties(pdb_file) # If values were successfully calculated, add to the results list if sasa_value is not None: results.append([pdb_file, sasa_value, mlp_value, electrostatic_value]) else: results.append([pdb_file, "Error", "Error", "Error"]) # Define the output CSV file name output_csv = "protein_properties.csv" # Save the results to CSV save_results_to_csv(results, output_csv) print(f"Results saved to {output_csv}") We ran this code in ChimeraX and it managed to run without any error message. However, when we opened the saved csv file, the file had the following printed: '[path to PDB file] Error, Error, Error.' However, we can't seem to find what went wrong with the code to result in this output. In addition, when we run the code in ChimeraX, the protein structures seem to become superimposed on each other and we were wondering if there was a way to overcome this? Any help and advice is greatly appreciated! Thank you for your time!

Well, I’m pretty sure there was an error message printed to the log, namely “Error processing PDB-file-name: details-of-error” because run(“close all”) is wrong. It needs to be run(session, “close all”). Your exception handler, after printing its message should do “raise” rather than “return None, None, None”. That’s why your CSV file has '[path to PDB file] Error, Error, Error.’ in it — trying to output None to the file is an error. --Eric Eric Pettersen UCSF Computer Graphics Lab
On Mar 13, 2025, at 7:58 AM, mishra.ananya.163--- via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Thank you so much for your help!
We tried running the following code: # Function to calculate the properties for each PDB file def calculate_properties(pdb_file): try: # Open the PDB file in ChimeraX run(session, f"open {pdb_file}")
# Calculate SASA (Solvent Accessible Surface Area) run(session, "surface") sasa_value = run(session, "measure sasa")
# Calculate Mean MLP (Mean Molecular Lipophilicity Potential) mlp_value = run(session, "mlp")
# Calculate Mean Electrostatic Potential electrostatic_value = run(session, "coulombic")
# Close the model to free memory run("close all")
return sasa_value, mlp_value, electrostatic_value except Exception as e: print(f"Error processing {pdb_file}: {e}") return None, None, None
# Function to save results to a CSV file def save_results_to_csv(results, output_file): with open(output_file, mode='w', newline='') as file: writer = csv.writer(file) writer.writerow(["PDB File", "SASA", "MLP", "Electrostatic Potential"]) for result in results: writer.writerow(result)
# List of PDB files (replace with your actual file paths) pdb_files = [ r'/Users/nikhita/Downloads/WT_EGFR.pdb', r'/Users/nikhita/Downloads/WT_MTOR.pdb' ]
# List to store the results results = []
# Loop through the PDB files and calculate the properties for pdb_file in pdb_files: print(f"Processing {pdb_file}...") sasa_value, mlp_value, electrostatic_value = calculate_properties(pdb_file)
# If values were successfully calculated, add to the results list if sasa_value is not None: results.append([pdb_file, sasa_value, mlp_value, electrostatic_value]) else: results.append([pdb_file, "Error", "Error", "Error"])
# Define the output CSV file name output_csv = "protein_properties.csv"
# Save the results to CSV save_results_to_csv(results, output_csv)
print(f"Results saved to {output_csv}")
We ran this code in ChimeraX and it managed to run without any error message. However, when we opened the saved csv file, the file had the following printed: '[path to PDB file] Error, Error, Error.' However, we can't seem to find what went wrong with the code to result in this output. In addition, when we run the code in ChimeraX, the protein structures seem to become superimposed on each other and we were wondering if there was a way to overcome this? Any help and advice is greatly appreciated! Thank you for your time! _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/

Dear Eric, Thank you for your help! We were able to run the aforementioned code successfully. However, we then made some changes to our code, which now involves he usage of the pandas module. However, we are having some difficulty trying to use pandas in Chimerax as we get the error "no module named pandas". We searched about this online and tried to download pandas for Chimerax via the terminal in Macbook but we got the error "permission denied". Here is the error that we got: nikhita@nikhitas-laptop ~ % /Users/nikhita/Desktop/ChimeraX-1.9 -m pip install pandas zsh: permission denied: /Users/nikhita/Desktop/ChimeraX-1.9 Any help would be greatly appreciated!

Hi Mishra, The easier way to install pandas into ChimeraX is to use the command “pip install pandas” in the ChimeraX command line. You can also install it via the Unix shell like you were trying to do, but you have to use the actual ChimeraX executable file, not the ChimeraX app folder which contains the executable and many other files/folder as well — so namely: /Users/nikhita/Desktop/ChimeraX-1.9.app/Contents/bin/ChimeraX -m pip install pandas —user --Eric
On Mar 17, 2025, at 5:56 AM, mishra.ananya.163--- via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Dear Eric,
Thank you for your help! We were able to run the aforementioned code successfully. However, we then made some changes to our code, which now involves he usage of the pandas module. However, we are having some difficulty trying to use pandas in Chimerax as we get the error "no module named pandas". We searched about this online and tried to download pandas for Chimerax via the terminal in Macbook but we got the error "permission denied".
Here is the error that we got: nikhita@nikhitas-laptop ~ % /Users/nikhita/Desktop/ChimeraX-1.9 -m pip install pandas zsh: permission denied: /Users/nikhita/Desktop/ChimeraX-1.9
Any help would be greatly appreciated! _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/
participants (4)
-
Elaine Meng
-
Eric Pettersen
-
mishra.ananya.163@gmail.com
-
Tom Goddard