Dear Prof Pettersen,
Thank you so much for your advice. So far I managed to operate in chimeraX and now I can see the outputs of my script. righ now I'm running the following:
# -*- coding: utf-8 -*-
import os
from chimerax.core.commands import run
# Funzione principale che accetta la sessione
def process_pdb_files(session):
# Specifica la cartella con i file PDB
folder_path = "C:/Users/utente/Desktop" # Modifica il percorso della cartella
# Stringa da cercare nei file
search_string = "A3a"
# Lista dei file PDB nella cartella
file_names = [fn for fn in os.listdir(folder_path) if fn.endswith(".pdb")]
# Stampa dei file trovati nella cartella per debugging
print("File trovati nella cartella:", file_names)
# Loop su ogni file che contiene 'search_string' nel nome
for pdb_file in file_names:
if search_string in pdb_file:
pdb_path = os.path.join(folder_path, pdb_file)
# Apre il file PDB
print(f"Apertura del file {pdb_file}...")
run(session, f"open {pdb_path}")
# Calcola i clash (comando corretto per ChimeraX)
run(session, "clashes")
# Verifica se ci sono clash
clashes_found = False
for m in session.models:
if getattr(m, 'category', None) == "contacts":
clashes_found = len(m.pseudoBonds) > 0
if clashes_found:
break
# Se ci sono clash, elimina il file
if clashes_found:
os.remove(pdb_path)
print(f"Clash trovati, il file {pdb_file} è stato eliminato.")
else:
print(f"Nessun clash trovato per {pdb_file}.")
# Chiude il modello dopo averlo processato
run(session, "close all")
# Questa parte assicura che la funzione venga chiamata correttamente
def main(session):
process_pdb_files(session)
# Quando esegui lo script in ChimeraX, la sessione viene passata automaticamente
main(session)
AND I GOT THE FOLLOWING OUTPUT:
runscript C:/Users/utente/Desktop/chimera_script2.pyFile trovati nella cartella: ['A3a_structure_1.pdb', 'A3a_structure_2.pdb', 'A3a_structure_3.pdb', 'A3a_structure_4.pdb', 'A3a_structure_5.pdb']
Apertura del file A3a_structure_1.pdb...
open C:/Users/utente/Desktop\A3a_structure_1.pdb
Chain information for A3a_structure_1.pdb #1
Chain
Description
0 2 4 6 8 C E G I K M O Q S U W Y a c e g i k m o q s u w y
No description available
1 3 5 7 9 B D F H J L N P R T V X Z b d f h j l n p r t v x z
No description available
A
No description available
clashes84336 clashes
Nessun clash trovato per A3a_structure_1.pdb.
close allApertura del file A3a_structure_2.pdb...
open C:/Users/utente/Desktop\A3a_structure_2.pdb
Chain information for A3a_structure_2.pdb #1
Chain
Description
0 2 4 6 8 C E G I K M O Q S U W Y a c e g i k m o q s u w y
No description available
1 3 5 7 9 B D F H J L N P R T V X Z b d f h j l n p r t v x z
No description available
A
No description available
clashes655434 clashes
Nessun clash trovato per A3a_structure_2.pdb.
close allApertura del file A3a_structure_3.pdb...
open C:/Users/utente/Desktop\A3a_structure_3.pdb
Chain information for A3a_structure_3.pdb #1
Chain
Description
0 2 4 6 8 C E G I K M O Q S U W Y a c e g i k m o q s u w y
No description available
1 3 5 7 9 B D F H J L N P R T V X Z b d f h j l n p r t v x z
No description available
A
No description available
clashes626886 clashes
Nessun clash trovato per A3a_structure_3.pdb.
close allApertura del file A3a_structure_4.pdb...
open C:/Users/utente/Desktop\A3a_structure_4.pdb
Chain information for A3a_structure_4.pdb #1
Chain
Description
0 2 4 6 8 C E G I K M O Q S U W Y a c e g i k m o q s u w y
No description available
1 3 5 7 9 B D F H J L N P R T V X Z b d f h j l n p r t v x z
No description available
A
No description available
clashes482406 clashes
Nessun clash trovato per A3a_structure_4.pdb.
close allApertura del file A3a_structure_5.pdb...
open C:/Users/utente/Desktop\A3a_structure_5.pdb
Chain information for A3a_structure_5.pdb #1
Chain
Description
0 2 4 6 8 C E G I K M O Q S U W Y a c e g i k m o q s u w y
No description available
1 3 5 7 9 B D F H J L N P R T V X Z b d f h j l n p r t v x z
No description available
A
No description available
clashes315894 clashes
Nessun clash trovato per A3a_structure_5.pdb.
close all
WHAT ELUDES ME IS THAT FOR EACH STRUCTURE CHIMERA FINDS LOT OF CLASHES BUT THEN RETURNS THE STATMENT "NO CLASH FOUND FOR STRUCTURE X". Why is that? I know these structures have lots of overlapping atoms and it also seems that chimera counts the class "clashes". But maybe it also includes contacts?
I would like to count only steric clashes and atoms superposition which makes the structure impossible.
Thanks in advance for your help.
Best regards,
Valerio Chiarini
Il 2025-02-12 21:06 Eric Pettersen via Chimera-users ha scritto:
Hi Valerio,
I should preface things by saying that this script would be
considerably easier to write in ChimeraX, because in ChimeraX the
"runCommand" equivalent actually returns results from the command
instead of nothing. So in ChimeraX you can directly determine if the
clash-finding command actually found any clashes.
So clearly the body of your 'if' statement never executed since it
includes illegal statements that would have produced errors if the
body of the 'if' statement had been executed, whereas you got no
output. So the first thing is put "print file_names" right after the
line that sets files_names and see if any of the file names contain
your search string ("xxx"). If none of them do, then you need to
figure out why: is folder_path wrong?; is search_string wrong?; do the
files not end in .pdb?; etc.
In addition, I can see some problems even if the 'if' statement body
had executed. You don't close the models at the end, so they will
build up and "findclash" will find more and more clashes. Your actual
findclash command needs to be "findclash #0 test self". There is no
"chimera.clashClashList". Probably the simplest way to determine if
clashes were found is checking if the clashes pseudobond group has any
pseudobonds in it. You can do that with:
for m in chimera.openModels.list(hidden=True):
if getattr(m, 'category', None) == "contacts":
clashes_found = len(m.pseudoBonds) > 0
break
--Eric
Eric Pettersen
UCSF Computer Graphics Lab
On Feb 12, 2025, at 2:23 AM, valerio chiarini via Chimera-users
<chimera-users@cgl.ucsf.edu> wrote:
Dear Responsible,
I am working on a script that should iterate through several
structures, check the structures for clashes among all atoms, and
eliminate the pdb in any clashes are found.
Here is what I have worked out so far:
# -*- coding: utf-8 -*-
import os
from chimera import runCommand as rc
from chimera import replyobj
import chimera
# Specify folder
folder_path = "/gporq3/store_0/usr/chiarini/chroma/chroma/"
# String to be found
search_string = "xxx"
# List of files in the folder
file_names = [fn for fn in os.listdir(folder_path) if
fn.endswith(".pdb")]
print("File trovati nella cartella:" + str(file_names))
# Loop on every file containing 'search_string' in the name
for pdb_file in file_names:
if search_string in pdb_file:
pdb_path = os.path.join(folder_path, pdb_file)
# Open the PDB
rc("open {}".format(pdb_path))
# Calculates clashes
rc("findclash")
rc("wait")
# Verify if any clashes are found
clashes = chimera.clashClashList()
if clashes:
# If clashes are found eliminates the file
os.remove(pdb_path)
print("Clash trovati, il file {} è stato
eliminato.".format(pdb_file))
else:
# If no clash, exit normally
print("Nessun clash trovato per {}.".format(pdb_file))
But no analisys is done at all. I have been searching through the
script page (https://www.rbvi.ucsf.edu/trac/chimera/wiki/Scripts) in
order to found some clue on this function but so far I have found
none.
Could you help me on this issue?
Thank you in advance
Valerio Chiarini _______________________________________________
Chimera-users mailing list -- chimera-users@cgl.ucsf.edu
To unsubscribe send an email to chimera-users-leave@cgl.ucsf.edu
Archives:
https://mail.cgl.ucsf.edu/mailman/archives/list/chimera-users@cgl.ucsf.edu/
_______________________________________________
Chimera-users mailing list -- chimera-users@cgl.ucsf.edu
To unsubscribe send an email to chimera-users-leave@cgl.ucsf.edu
Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimera-users@cgl.ucsf.edu/
--
Dr. Valerio Chiarini
_Senior Scientist_
Proteins & Monoclona Antibodies Department – Takis Biotech
c/o Tecnopolo
Via di Castel Romano, 100
00128 Rome, Italy
Tel.: +39 06-50576077
Fax: +39 06-50576710
Email: chiarini@takisbiotech.it
Web: https://urldefense.proofpoint.com/v2/url?u=http-3A__www.takisbiotech.it&d=DwIDaQ&c=euGZstcaTDllvimEN8b7jXrwqOf-v5A_CdpgnVfiiMM&r=AnLbjfzj4A4gVWflERdQcNZUEpTJryfgdkg4779VL5A&m=WctdkVI3bU6ZB5AYRFX4pbJDI1WGXn1cYThIb5wbBX6IOMa74PN_emRBlFkbG2xv&s=ntuB_R3Y28Ozj_g3c42dM-o31hWODDm2cffJPyeyfbE&e=
D_.lgs. 196/03_
_Le informazioni contenute in questa comunicazione e gli eventuali
documenti allegati hanno carattere confidenziale, sono tutelate dal segreto
professionale e sono ad uso esclusivo del destinatario. Nel caso questa
comunicazione Vi sia pervenuta per errore, Vi informiamo che la sua
diffusione e riproduzione è contraria alla legge e preghiamo di darci
prontamente avviso e di cancellare quanto ricevuto. __Grazie._
_This e-mail message and any files transmitted with it are subject to
attorney-client privilege and contain confidential information intended
only for the person(s) to whom it is addressed. If you are not the intended
recipient, you are hereby notified that any use or distribution of this
e-mail is strictly prohibited: please notify the sender and delete the
original message. __Thank you._