Re: [PyMOL] How to catch PyMOL command exception within a Python script

2019-02-22 Thread Thomas Evangelidis
Hi Thomas,

With regard to selections, sometimes a residue has missing atoms or is
non-standard amino acid. In the first case it is matched with another
residue in a second structure during the alignment and then when I try to
fit the two selections of atoms from the two structures I get the following
error:

 Calculating RMSD between pocket of model 2hduA and 2r9wA.
> ExecutiveRMS-Error: Atom counts between selections don't match (799 vs 797)
>  Executive: Error -- no atoms left after refinement!
> RMSD = -1.00


Can you think of a clever way to exclude amino acids with missing atoms or
non-standard ones from pair_fit() or rms_cur()?

Best,
Thomas





On Fri, 22 Feb 2019 at 12:32, Thomas Holder 
wrote:

> Hi Thomas,
>
> In general, the PyMOL API should raise pymol.CmdException if things go
> wrong. But in case of cmd.pair_fit() this wasn't happening (see my fix that
> I pushed few minutes ago:
> https://github.com/schrodinger/pymol-open-source/commit/b26d91c40d20344fef511ea9d6bb664a93f1bb4a
> )
>
> cmd.select() correctly raises an exception, so if you want to make a
> script more robust against selection failures, you could always create a
> named selection first to check if it's valid.
>
> tmpsele1 = cmd.get_unused_name('_sele1')
> try:
> cmd.select(tmpsele1, someexpression, 0)
> except pymol.CmdException:
> print('invalid selection')
> finally:
> cmd.delete(tmpsele1)
>
>
> Cheers,
>   Thomas
>
> > On Feb 22, 2019, at 12:11 PM, Thomas Evangelidis 
> wrote:
> >
> > Hi Thomas,
> >
> > This is great! I can even include more atom types in the selection.
> > Just for the record, is it possible to catch PyMOL exceptions like
> "Selector-Error" from within a Python script? Is there any general strategy
> to select which exception type to look for? In the past, I was catching
> exceptions from 'tmalign' with "except AssertionError:" which doesn't work
> for "Selector-Error".
> >
> > Best,
> > Thomas
> >
> >
> > --
> > ==
> > Dr Thomas Evangelidis
> > Research Scientist
> > IOCB - Institute of Organic Chemistry and Biochemistry of the Czech
> Academy of Sciences
> > Prague, Czech Republic
> >   &
> > CEITEC - Central European Institute of Technology
> > Brno, Czech Republic
> >
> > email: teva...@gmail.com
> > website: https://sites.google.com/site/thomasevangelidishomepage/
>
> --
> Thomas Holder
> PyMOL Principal Developer
> Schrödinger, Inc.
>
>

-- 

==

Dr Thomas Evangelidis

Research Scientist

IOCB - Institute of Organic Chemistry and Biochemistry of the Czech Academy
of Sciences 
Prague, Czech Republic
  &
CEITEC - Central European Institute of Technology 
Brno, Czech Republic

email: teva...@gmail.com

website: https://sites.google.com/site/thomasevangelidishomepage/
___
PyMOL-users mailing list
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net
Unsubscribe: 
https://sourceforge.net/projects/pymol/lists/pymol-users/unsubscribe

Re: [PyMOL] How to catch PyMOL command exception within a Python script

2019-02-22 Thread Thomas Holder
Hi Thomas,

In general, the PyMOL API should raise pymol.CmdException if things go wrong. 
But in case of cmd.pair_fit() this wasn't happening (see my fix that I pushed 
few minutes ago: 
https://github.com/schrodinger/pymol-open-source/commit/b26d91c40d20344fef511ea9d6bb664a93f1bb4a
 )

cmd.select() correctly raises an exception, so if you want to make a script 
more robust against selection failures, you could always create a named 
selection first to check if it's valid.

tmpsele1 = cmd.get_unused_name('_sele1')
try:
cmd.select(tmpsele1, someexpression, 0)
except pymol.CmdException:
print('invalid selection')
finally:
cmd.delete(tmpsele1)


Cheers,
  Thomas

> On Feb 22, 2019, at 12:11 PM, Thomas Evangelidis  wrote:
> 
> Hi Thomas,
> 
> This is great! I can even include more atom types in the selection.
> Just for the record, is it possible to catch PyMOL exceptions like 
> "Selector-Error" from within a Python script? Is there any general strategy 
> to select which exception type to look for? In the past, I was catching 
> exceptions from 'tmalign' with "except AssertionError:" which doesn't work 
> for "Selector-Error".
> 
> Best,
> Thomas
> 
> 
> -- 
> ==
> Dr Thomas Evangelidis
> Research Scientist
> IOCB - Institute of Organic Chemistry and Biochemistry of the Czech Academy 
> of Sciences
> Prague, Czech Republic
>   & 
> CEITEC - Central European Institute of Technology
> Brno, Czech Republic 
> 
> email: teva...@gmail.com
> website: https://sites.google.com/site/thomasevangelidishomepage/

--
Thomas Holder
PyMOL Principal Developer
Schrödinger, Inc.



___
PyMOL-users mailing list
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net
Unsubscribe: 
https://sourceforge.net/projects/pymol/lists/pymol-users/unsubscribe

Re: [PyMOL] How to catch PyMOL command exception within a Python script

2019-02-22 Thread Thomas Evangelidis
Hi Thomas,

This is great! I can even include more atom types in the selection.
Just for the record, is it possible to catch PyMOL exceptions like
"Selector-Error" from within a Python script? Is there any general strategy
to select which exception type to look for? In the past, I was catching
exceptions from 'tmalign' with "except AssertionError:" which doesn't work
for "Selector-Error".

Best,
Thomas


On Fri, 22 Feb 2019 at 11:28, Thomas Holder 
wrote:

> Hi Thomas,
>
> Getting rid of the string length limitations would need some major
> refactoring. There is currently no good workaround, other than avoiding
> such long selections.
>
> In this particular case, the script could use cmd.select_list() instead of
> concatenating the index list to a string:
>
> cmd.select_list('sel1', obj1, [int(i) for i in id1], mode='index')
> cmd.select_list('sel2', obj2, [int(i) for i in id2], mode='index')
> cmd.pair_fit("sel1 and aln", "sel2 and aln")
> cmd.delete('sel1')
> cmd.delete('sel2')
>
> Hope that helps.
>
> Cheers,
>   Thomas
>
>
> > On Feb 22, 2019, at 9:32 AM, Thomas Evangelidis 
> wrote:
> >
> > Greetings,
> >
> > I am trying to run focus_alignment command (
> https://pymolwiki.org/index.php/Focus_alignment) from within a Python
> script with my own custom selection (I include CA+CB atoms instead of only
> CA as in the default). Sometimes the selection is very large and PyMOL
> cannot hand it:
> >
> > Selector-Error: Word too long. Truncated:
> > Selector-Error:
> 183+186+191+194+196+199+203+206+208+211+437+440+445+448+456+459+465+468+473+477+480+483+486+490+493+496+499+505+508+512+515+523+526+530+534+537+541+544+827+830+832+835+1138+1141+1150+1153+1155+115Selector-Error:
> Invalid selection name "730".
> > poly and 4kz6A and aln and index
> 183+186+191+194+196+199+203+206+208+211+437+440+445+448+456+459+465+468+473+477+480+483+486+490+493+496+499+505+508+512+515+523+526+530+534+537+541+544+827+830+832+835+1138+1141+1150+1153+1155+1158+1175+1178+1183+1421+1424+1428+1431+1647+1650+1655+1658+
> 730<--
> > Selector-Error: Word too long. Truncated:
> > Selector-Error:
> 216+219+224+227+229+232+236+239+241+244+479+482+487+490+498+501+507+510+515+519+522+525+528+532+535+538+541+547+550+554+557+565+568+572+576+579+583+586+873+876+878+881+1192+1195+1204+1207+1209+121Selector-Error:
> Invalid selection name "868".
> > poly and 2r9wA and aln and index
> 216+219+224+227+229+232+236+239+241+244+479+482+487+490+498+501+507+510+515+519+522+525+528+532+535+538+541+547+550+554+557+565+568+572+576+579+583+586+873+876+878+881+1192+1195+1204+1207+1209+1212+1229+1232+1237+1491+1494+1498+1501+1747+1750+1755+1758+
> 868<--
> > ExecutiveRMS-Error: No atoms selected.
> > Selector-Error: Word too long. Truncated:
> > Selector-Error:
> 183+186+191+194+196+199+203+206+208+211+437+440+445+448+456+459+465+468+473+477+480+483+486+490+493+496+499+505+508+512+515+523+526+530+534+537+541+544+827+830+832+835+1138+1141+1150+1153+1155+115Selector-Error:
> Word too long. Truncated:
> > Selector-Error:
> 216+219+224+227+229+232+236+239+241+244+479+482+487+490+498+501+507+510+515+519+522+525+528+532+535+538+541+547+550+554+557+565+568+572+576+579+583+586+873+876+878+881+1192+1195+1204+1207+1209+121Selector-Error:
> Invalid selection name "730".
> > ( ( poly and 4kz6A and aln and index
> 183+186+191+194+196+199+203+206+208+211+437+440+445+448+456+459+465+468+473+477+480+483+486+490+493+496+499+505+508+512+515+523+526+530+534+537+541+544+827+830+832+835+1138+1141+1150+1153+1155+1158+1175+1178+1183+1421+1424+1428+1431+1647+1650+1655+1658+
> 730 ) in ( poly and 2r9wA and aln and index
> 216+219+224+227+229+232+236+239+241+244+479+482+487+490+498+501+507+510+515+519+522+525+528+532+535+538+541+547+550+554+557+565+568+572+576+579+583+586+873+876+878+881+1192+1195+1204+1207+1209+1212+1229+1232+1237+1491+1494+1498+1501+1747+1750+1755+1758+
> 868 ) )<--
> >
> > Is there a way to ask PyMOL to accept longer selection strings?
> > Alternatively, is it possible to catch this exception from within the
> script using "try: ... except :" statement?
> >
> > Thanks in advance.
> > Thomas
> >
> > --
> > ==
> > Dr Thomas Evangelidis
> > Research Scientist
> > IOCB - Institute of Organic Chemistry and Biochemistry of the Czech
> Academy of Sciences
> > Prague, Czech Republic
> >   &
> > CEITEC - Central European Institute of Technology
> > Brno, Czech Republic
> >
> > email: teva...@gmail.com
> > website: https://sites.google.com/site/thomasevangelidishomepage/
>
> --
> Thomas Holder
> PyMOL Principal Developer
> Schrödinger, Inc.
>
>

-- 

==

Dr Thomas Evangelidis

Research Scientist

IOCB - Institute of Organic Chemistry and Biochemistry of the Czech Academy
of Sciences 
Prague, Czech Republic
  &
CEITEC - Central European Institute of Technology 

Re: [PyMOL] How to catch PyMOL command exception within a Python script

2019-02-22 Thread Thomas Holder
Hi Thomas,

Getting rid of the string length limitations would need some major refactoring. 
There is currently no good workaround, other than avoiding such long selections.

In this particular case, the script could use cmd.select_list() instead of 
concatenating the index list to a string:

cmd.select_list('sel1', obj1, [int(i) for i in id1], mode='index')
cmd.select_list('sel2', obj2, [int(i) for i in id2], mode='index')
cmd.pair_fit("sel1 and aln", "sel2 and aln")
cmd.delete('sel1')
cmd.delete('sel2')

Hope that helps.

Cheers,
  Thomas


> On Feb 22, 2019, at 9:32 AM, Thomas Evangelidis  wrote:
> 
> Greetings,
> 
> I am trying to run focus_alignment command 
> (https://pymolwiki.org/index.php/Focus_alignment) from within a Python script 
> with my own custom selection (I include CA+CB atoms instead of only CA as in 
> the default). Sometimes the selection is very large and PyMOL cannot hand it:
> 
> Selector-Error: Word too long. Truncated:
> Selector-Error: 
> 183+186+191+194+196+199+203+206+208+211+437+440+445+448+456+459+465+468+473+477+480+483+486+490+493+496+499+505+508+512+515+523+526+530+534+537+541+544+827+830+832+835+1138+1141+1150+1153+1155+115Selector-Error:
>  Invalid selection name "730".
> poly and 4kz6A and aln and index 
> 183+186+191+194+196+199+203+206+208+211+437+440+445+448+456+459+465+468+473+477+480+483+486+490+493+496+499+505+508+512+515+523+526+530+534+537+541+544+827+830+832+835+1138+1141+1150+1153+1155+1158+1175+1178+1183+1421+1424+1428+1431+1647+1650+1655+1658+
>  730<--
> Selector-Error: Word too long. Truncated:
> Selector-Error: 
> 216+219+224+227+229+232+236+239+241+244+479+482+487+490+498+501+507+510+515+519+522+525+528+532+535+538+541+547+550+554+557+565+568+572+576+579+583+586+873+876+878+881+1192+1195+1204+1207+1209+121Selector-Error:
>  Invalid selection name "868".
> poly and 2r9wA and aln and index 
> 216+219+224+227+229+232+236+239+241+244+479+482+487+490+498+501+507+510+515+519+522+525+528+532+535+538+541+547+550+554+557+565+568+572+576+579+583+586+873+876+878+881+1192+1195+1204+1207+1209+1212+1229+1232+1237+1491+1494+1498+1501+1747+1750+1755+1758+
>  868<--
> ExecutiveRMS-Error: No atoms selected.
> Selector-Error: Word too long. Truncated:
> Selector-Error: 
> 183+186+191+194+196+199+203+206+208+211+437+440+445+448+456+459+465+468+473+477+480+483+486+490+493+496+499+505+508+512+515+523+526+530+534+537+541+544+827+830+832+835+1138+1141+1150+1153+1155+115Selector-Error:
>  Word too long. Truncated:
> Selector-Error: 
> 216+219+224+227+229+232+236+239+241+244+479+482+487+490+498+501+507+510+515+519+522+525+528+532+535+538+541+547+550+554+557+565+568+572+576+579+583+586+873+876+878+881+1192+1195+1204+1207+1209+121Selector-Error:
>  Invalid selection name "730".
> ( ( poly and 4kz6A and aln and index 
> 183+186+191+194+196+199+203+206+208+211+437+440+445+448+456+459+465+468+473+477+480+483+486+490+493+496+499+505+508+512+515+523+526+530+534+537+541+544+827+830+832+835+1138+1141+1150+1153+1155+1158+1175+1178+1183+1421+1424+1428+1431+1647+1650+1655+1658+
>  730 ) in ( poly and 2r9wA and aln and index 
> 216+219+224+227+229+232+236+239+241+244+479+482+487+490+498+501+507+510+515+519+522+525+528+532+535+538+541+547+550+554+557+565+568+572+576+579+583+586+873+876+878+881+1192+1195+1204+1207+1209+1212+1229+1232+1237+1491+1494+1498+1501+1747+1750+1755+1758+
>  868 ) )<--
> 
> Is there a way to ask PyMOL to accept longer selection strings?
> Alternatively, is it possible to catch this exception from within the script 
> using "try: ... except :" statement?
> 
> Thanks in advance.
> Thomas
> 
> -- 
> ==
> Dr Thomas Evangelidis
> Research Scientist
> IOCB - Institute of Organic Chemistry and Biochemistry of the Czech Academy 
> of Sciences
> Prague, Czech Republic
>   & 
> CEITEC - Central European Institute of Technology
> Brno, Czech Republic 
> 
> email: teva...@gmail.com
> website: https://sites.google.com/site/thomasevangelidishomepage/

--
Thomas Holder
PyMOL Principal Developer
Schrödinger, Inc.



___
PyMOL-users mailing list
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net
Unsubscribe: 
https://sourceforge.net/projects/pymol/lists/pymol-users/unsubscribe