in python version I have got it

# to be run with PyMOL:
#pymol -ckqr pymol_cut_off.py
################ cut_off.py #####
from pymol import cmd
pdb = "final.pdb"
chains_array = ["A", "B"] # two chains will be cuted

for chain in chains_array:
    cmd.load(pdb)
    cmd.alter('chain ' + chain, 'chain=""')


cmd.set('pdb_use_ter_records', 1)
cmd.set('retain_order', 1)
cmd.save('output_without'+"".join(chains_array) + '.pdb')

now the question would it be possible to do the same but in my bash script?

вт, 25 июн. 2019 г. в 16:20, James Starlight <jmsstarli...@gmail.com>:
>
> OK Lorenzo, thank you !
>
> As an alternative question, would it be possible to put that loop
> while renaming of the chains in the processed PBD within the bash
> loop?
>
> Here is an idea
>
> #!/bin/bash
> # this script rename chains in pdb to "empty" chain
> pdb="my.pdb"
> output=$(pwd)
>
> # chain array is provided in a shell array
> chains=('A' 'B')
>
> # create several pdbs without individual chains
> #pymol -cQkd "
> pymol -c -d "
> # I need to add loop within PYMOL over the elements of external arrays
> for chains
> # mb for i in chains:
> cmd.load('${pdb}')
> cmd.alter('(chain $i)', 'chain=\"\"')
> cmd.set('pdb_use_ter_records', 1)
> cmd.set('retain_order', 1)
> # close the loop and save final output as 1 pdb
> cmd.save('${output}/output_withoutAB.pdb','all')
> "
>
> вт, 25 июн. 2019 г. в 16:14, James Starlight <jmsstarli...@gmail.com>:
> >
> > thanks so much Thomas, for this example!
> >
> > Actually, your python script does exactly what my bash script -
> > produces number of pdbs for each of the renamed chain.
> > I would like rather to produce at the end ONE pdb with all chains
> > renamed to empty chain...
> > I guess I need to save the result outside of the loop something like this
> >
> > ################ hop hey lalaley #####
> > from pymol import cmd
> > pdb = "Ev_complex_model_final.pdb"
> > chains_array = ["A", "B"] # add more chains in case of more complex pdb
> >
> > # loop over chains to rename it
> > for chain in chains_array:
> >     cmd.load(pdb)
> >     cmd.alter('chain ' + chain, 'chain=""')
> >     cmd.delete('*')
> > ######################################
> >
> > # save output as pdb
> > # I need to add something in the name of output indicating how much
> > chains have been renamed
> > # like output_withoutAB.pdb
> > cmd.save('output_'  + '.pdb')
> >
> > thanks in advance for help!
> >
> > вт, 25 июн. 2019 г. в 16:03, Thomas Holder <thomas.hol...@schrodinger.com>:
> > >
> > > > generally if I integrate a pymol silent script inside my
> > > > bash script, I do not need to use cmd.* syntax, right?
> > >
> > > Correct. The -d argument takes PyMOL commands, like a .pml script. Python 
> > > syntax is optional.
> > >
> > > Python syntax (cmd.*) is necessary and most useful if you write a Python 
> > > script (.py extension) and run that with PyMOL. You could write your 
> > > multi-chains loop as a Python script:
> > >
> > > ################ example.py ##########
> > > from pymol import cmd
> > > pdb = "my.pdb"
> > > chains_arrays = ["A", "B", "C", "D", "E", "F", "G"]
> > >
> > > for chain in chains_array:
> > >     cmd.load(pdb)
> > >     cmd.alter('chain ' + chain, 'chain=""')
> > >     cmd.save('output_' + chain + '.pdb')
> > >     cmd.delete('*')
> > > ######################################
> > >
> > > Then run it with PyMOL:
> > > pymol -ckqr example.py
> > >
> > > See also:
> > > https://pymolwiki.org/index.php/Launching_From_a_Script
> > > https://pymolwiki.org/index.php/Python_Integration
> > >
> > > Cheers,
> > >   Thomas
> > >
> > > > On Jun 25, 2019, at 3:08 PM, James Starlight <jmsstarli...@gmail.com> 
> > > > wrote:
> > > >
> > > > one extra programming question:
> > > >
> > > > imagine now in my pdb I have severals chain which I would like to
> > > > rename to blank chain.
> > > >
> > > > I can do it simply like this
> > > > # a case for 3 chains to be renamed
> > > >
> > > > #!/bin/bash
> > > > pdb="my.pdb"
> > > > output=$(pwd)
> > > > pymol -c -d "
> > > > cmd.load('${pdb}')
> > > > cmd.alter('(chain A)', 'chain=\"\"')
> > > > cmd.alter('(chain B)', 'chain=\"\"')
> > > > cmd.alter('(chain C)', 'chain=\"\"')
> > > > cmd.save('${output}/output.pdb','all')
> > > > "
> > > >
> > > > or for multi-chain protein I can alternatively create external loop,
> > > > thus running pymol 3 times iteratively (which is not good realization)
> > > > providin array info from external shell session
> > > >
> > > > # this example save 7 different pdbs renaming one chain in each of them
> > > > #!/bin/bash
> > > > pdb="my.pdb"
> > > > output=$(pwd)
> > > > chains_arrays=( A B C D E F G )
> > > >
> > > > for i in "$chains_array[@]}"; do
> > > > pymol -c -d "
> > > > cmd.load('${pdb}')
> > > > cmd.alter('(chain $i)', 'chain=\"\"')
> > > > cmd.save('${output}/output_$i.pdb','all')
> > > > "
> > > > done
> > > >
> > > > would it be possible rather to make an array and loop inside the pymol
> > > > to rename all chains into the blank chain during one execution of
> > > > pymol?
> > > >
> > > > Thanks in advance!
> > > >
> > > > вт, 25 июн. 2019 г. в 14:50, James Starlight <jmsstarli...@gmail.com>:
> > > >>
> > > >> I have got the idea!
> > > >> thank you so much Thomas!
> > > >> One question: generally if I integrate a pymol silent script inside my
> > > >> bash script, I do not need to use cmd.* syntax, right?  In what cases
> > > >> cmd.* sytax might be usefull?
> > > >>
> > > >> Thank you again!
> > > >>
> > > >> вт, 25 июн. 2019 г. в 12:05, Thomas Holder 
> > > >> <thomas.hol...@schrodinger.com>:
> > > >>>
> > > >>>
> > > >>>> On Jun 25, 2019, at 11:48 AM, James Starlight 
> > > >>>> <jmsstarli...@gmail.com> wrote:
> > > >>>>
> > > >>>> so what I need is just to update my pymol, keep using the same 
> > > >>>> command?
> > > >>>
> > > >>> Yes
> > > >>>
> > > >>>> P.S.would the following integration of the code into bash script be
> > > >>>> usefull to remove chains in no gui mode?
> > > >>>>
> > > >>>> pymol -cQkd "
> > > >>>> from pymol import cmd
> > > >>>> fetch $pdb, type=pdb, tmp
> > > >>>> cmd.alter('(chain A)',chain='')
> > > >>>> "
> > > >>>> I am not sure whether I used here cmd.alter in correct way ..
> > > >>>
> > > >>>
> > > >>> With fetch, use "async=0" or use Python syntax. And keyword arguments 
> > > >>> (type=) must be after positional arguments (tmp).
> > > >>>
> > > >>> It's easier if you don't use Python syntax for alter, otherwise 
> > > >>> you'll need three levels of nested quotes, which gets ugly:
> > > >>>
> > > >>> pymol -cQkd "
> > > >>> fetch $pdb, tmp, type=pdb, async=0
> > > >>> alter (chain A), chain=''
> > > >>> "
> > > >>>
> > > >>> With Python syntax (note the ugly escaping of quotes):
> > > >>>
> > > >>> pymol -cQkd "
> > > >>> cmd.fetch('$pdb', 'tmp', type='pdb')
> > > >>> cmd.alter('(chain A)', 'chain=\"\"')
> > > >>> "
> > > >>>
> > > >>> Cheers,
> > > >>>  Thomas
> > > >>>
> > > >>> --
> > > >>> Thomas Holder
> > > >>> PyMOL Principal Developer
> > > >>> Schrödinger, Inc.
> > > >>>
> > >
> > > --
> > > 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

Reply via email to