<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pymol.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Bhannigan</id>
	<title>PyMOL Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pymol.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Bhannigan"/>
	<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php/Special:Contributions/Bhannigan"/>
	<updated>2026-04-24T17:08:08Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Split_Object_Along_Axis&amp;diff=10344</id>
		<title>Split Object Along Axis</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Split_Object_Along_Axis&amp;diff=10344"/>
		<updated>2010-04-13T20:54:22Z</updated>

		<summary type="html">&lt;p&gt;Bhannigan: Created page with '== Overview == I have a number of small molecules that I am looking at.  Many of these small molecules have distinct sections which are connected by a single bond.  In a separate…'&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
I have a number of small molecules that I am looking at.  Many of these small molecules have distinct sections which are connected by a single bond.  In a separate program I am writing, I would like to rotate each section around the given bond.  I wanted a script that would allow me to select a bond, and then generate 2 selections: one for the selection of all atoms that are on one side of this bond, and the other selection for the atoms on the other side of the bond.  If there is a 2nd bond which connects the 2 sections of atoms, the script will still run and terminate, but the two selections won't make much sense!&lt;br /&gt;
&lt;br /&gt;
To use, just call splitObjAlongAxis(axisSelection, outFileName)&lt;br /&gt;
where:&lt;br /&gt;
axisSelection is a selection that includes 2 atoms.  These atoms define the axis which we are splitting across. &lt;br /&gt;
outFileName is an optional file name where the script will spit three lines.  The first line will be the two atom id's of the axis. The second line will be a list of atom id's in the selection generated, and the third line will be a list of atom id's in the second selection generated.&lt;br /&gt;
&lt;br /&gt;
== Source Code ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def findAttachedAtoms(objModel, atomIndex, excludeAtomIndex, atoms):&lt;br /&gt;
    atoms += [objModel.atom[atomIndex]]&lt;br /&gt;
    &lt;br /&gt;
    for b in objModel.bond:&lt;br /&gt;
        if((atomIndex in b.index) and (excludeAtomIndex not in b.index)):&lt;br /&gt;
            newAtomIndex = -1&lt;br /&gt;
            if(b.index[0] == atomIndex):&lt;br /&gt;
                newAtomIndex = b.index[1]&lt;br /&gt;
            else:&lt;br /&gt;
                newAtomIndex = b.index[0]&lt;br /&gt;
&lt;br /&gt;
            newAtom = objModel.atom[newAtomIndex]&lt;br /&gt;
            if(newAtom not in atoms):&lt;br /&gt;
                atoms += [newAtom]&lt;br /&gt;
                findAttachedAtoms(objModel, newAtomIndex, excludeAtomIndex, atoms)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def getNewSelection(objModel, atomId, excludeAtomId):&lt;br /&gt;
    atomIndex = -1&lt;br /&gt;
    excludeAtomIndex = -1&lt;br /&gt;
&lt;br /&gt;
    for i in range(len(objModel.atom)):&lt;br /&gt;
        if(objModel.atom[i].id == atomId):&lt;br /&gt;
            atomIndex = i&lt;br /&gt;
        if(objModel.atom[i].id == excludeAtomId):&lt;br /&gt;
            excludeAtomIndex = i&lt;br /&gt;
&lt;br /&gt;
    atoms = []&lt;br /&gt;
    findAttachedAtoms(objModel, atomIndex, excludeAtomIndex, atoms)&lt;br /&gt;
&lt;br /&gt;
    return atoms&lt;br /&gt;
&lt;br /&gt;
def outputSelections(leftSel, rightSel, axisModel, outFileName, append):&lt;br /&gt;
    mode = 'w'&lt;br /&gt;
    if(append):&lt;br /&gt;
        mode = 'a'&lt;br /&gt;
&lt;br /&gt;
    of = open(outFileName, mode)&lt;br /&gt;
    line = str(axisModel.atom[0].id) + ',' + str(axisModel.atom[1].id) + '\n'&lt;br /&gt;
    of.write(line)&lt;br /&gt;
&lt;br /&gt;
    line = ''&lt;br /&gt;
    for a in leftSel:&lt;br /&gt;
        line += str(a.id) + ','&lt;br /&gt;
    of.write(line[0:-1] + '\n')&lt;br /&gt;
&lt;br /&gt;
    line = ''&lt;br /&gt;
    for a in rightSel:&lt;br /&gt;
        line += str(a.id) + ','&lt;br /&gt;
    of.write(line[0:-1] + '\n')&lt;br /&gt;
&lt;br /&gt;
    of.close()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def splitObjAlongAxis(objName, axisSelection, outFileName = '', append = False):&lt;br /&gt;
    objModel = cmd.get_model(objName)&lt;br /&gt;
    axisModel = cmd.get_model(axisSelection)&lt;br /&gt;
&lt;br /&gt;
    leftSel = []&lt;br /&gt;
    rightSel = []&lt;br /&gt;
&lt;br /&gt;
    try:&lt;br /&gt;
        leftSel = getNewSelection(objModel, axisModel.atom[0].id, axisModel.atom[1].id)&lt;br /&gt;
        rightSel = getNewSelection(objModel, axisModel.atom[1].id, axisModel.atom[0].id)&lt;br /&gt;
    except:&lt;br /&gt;
        print 'Error in splitObjAlongAxis!'&lt;br /&gt;
&lt;br /&gt;
    selection = ''&lt;br /&gt;
    for a in leftSel:&lt;br /&gt;
        selection += 'id ' + str(a.id) + ' or '&lt;br /&gt;
    selection = selection[0:-3]&lt;br /&gt;
    cmd.select('left',selection)&lt;br /&gt;
&lt;br /&gt;
    selection = ''&lt;br /&gt;
    for a in rightSel:&lt;br /&gt;
        selection += 'id ' + str(a.id) + ' or '&lt;br /&gt;
    selection = selection[0:-3]&lt;br /&gt;
    cmd.select('right',selection)&lt;br /&gt;
&lt;br /&gt;
    if(outFileName != ''):&lt;br /&gt;
        outputSelections(leftSel, rightSel, axisModel, outFileName, append)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Script_Library|Split Movement]]&lt;br /&gt;
[[Category:ObjSel_Scripts]]&lt;/div&gt;</summary>
		<author><name>Bhannigan</name></author>
	</entry>
	<entry>
		<id>https://wiki.pymol.org/index.php?title=Category:ObjSel_Scripts&amp;diff=3769</id>
		<title>Category:ObjSel Scripts</title>
		<link rel="alternate" type="text/html" href="https://wiki.pymol.org/index.php?title=Category:ObjSel_Scripts&amp;diff=3769"/>
		<updated>2010-04-02T17:17:46Z</updated>

		<summary type="html">&lt;p&gt;Bhannigan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [[ConnectedCloud]] &lt;br /&gt;
::Find connected clouds of objects in PyMOL&lt;br /&gt;
* [[Color Objects]]&lt;br /&gt;
:: Colors all objects differently (Python script).&lt;br /&gt;
* [[FindSeq]]&lt;br /&gt;
:: Find sequence or regular expression of amino acids in a protein.&lt;br /&gt;
* [[Get Coordinates I]]&lt;br /&gt;
:: Retrieves atom coordinates as Python objects.&lt;br /&gt;
* [[Get Coordinates II]]&lt;br /&gt;
:: Retrieves atom coordinates as Python array (list object).&lt;br /&gt;
* [[grepsel]] &lt;br /&gt;
:: Make named selections using regular expressions (protein sequence).&lt;br /&gt;
* [[List Selection]]&lt;br /&gt;
:: Prints a list of all residues in a selection (both Python and .pml).&lt;br /&gt;
* [[List Colors]]&lt;br /&gt;
:: Lists the color of all residues in a selection (both Python and .pml).&lt;br /&gt;
* [[List Secondary Structures]]&lt;br /&gt;
:: Secondary structures (both predefined and those calculated with the 'dss' command) can be exported as a long string ('HHHHLLLLSSS').&lt;br /&gt;
* [[Selection Exists]]&lt;br /&gt;
:: Python method that returns true if a selection of a given name exists.&lt;br /&gt;
* [[Split Movement]]&lt;br /&gt;
:: Moves two parts of one object into different directions.&lt;br /&gt;
* [[Split Object Along Axis]]&lt;br /&gt;
:: Splits an object into 2 pieces along a given axis.&lt;br /&gt;
* [[toGroup]]&lt;br /&gt;
:: Convert a multistate object into a group of single state objects.&lt;br /&gt;
* [[Zero_residues]]&lt;br /&gt;
:: Renumber residues such that the first residue is 0.  Useful for alignments.&lt;br /&gt;
&lt;br /&gt;
[[Category:Script_Library]]&lt;/div&gt;</summary>
		<author><name>Bhannigan</name></author>
	</entry>
</feed>