# Issue with Atom Selection mddf calculation (ComplexMixtures.jl from python)

**URL:** <https://discourse.julialang.org/t/issue-with-atom-selection-mddf-calculation-complexmixtures-jl-from-python/129604>\
**Category:** General Usage\
**Tags:** molecular-simulation\
**Created:** [June 3, 2025, 4:02pm UTC](https://discourse.julialang.org/t/issue-with-atom-selection-mddf-calculation-complexmixtures-jl-from-python/129604 "2025-06-03T16:02:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![SnehaSahuvs4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/snehasahuvs4/32/217139_2.png) [@SnehaSahuvs4](https://discourse.julialang.org/u/SnehaSahuvs4)\
**Post date:** [June 3, 2025, 4:02pm UTC](https://discourse.julialang.org/t/issue-with-atom-selection-mddf-calculation-complexmixtures-jl-from-python/129604/1 "2025-06-03T16:02:19Z")

</div>

Hi @lmiq

I’m encountering an issue when calculating the center of mass using cm.select(). Specifically, it seems that the selection is not correctly including all the specified residues.

For example, whether I use:  
protein = cm.select(atoms, “protein and resnum 7”)

or  
protein = cm.select(atoms, “protein and resnum 7 8 9 391 392 393 72”)

I observe that a similar number of solute atoms are being selected. Upon closer inspection, it looks like only the first residue ID is being considered during the calculation, even when multiple IDs are specified.

I’ve tried using a comma-separated list and other formats, but nothing seems to change the behavior. The script below runs without errors, but the selection appears incorrect:  
atoms = cm.readPDB(“\*.pdb”)  
protein = cm.select(atoms, “protein and resnum 7 8 9 391 392 393 72”)  
bgc = cm.select(atoms, “resname bgc”)

solute = cm.AtomSelection(protein, nmols=1)  
solvent = cm.AtomSelection(bgc, natomspermol=24) # 24 atoms per BGC molecule

trajectory = cm.Trajectory(“../\*.xtc”, solute, solvent)  
options4 = cm.Options(bulk\_range=(8.0, 12.0))  
results = cm.mddf(trajectory, options4)

cm.save(results, “./save.json”)  
print(“Results saved to save.json”)

Could you please advise on the correct syntax for selecting multiple residues, or let me know if this is a known issue?

Best regards,  
Sneha Sahu

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [June 3, 2025, 4:34pm UTC](https://discourse.julialang.org/t/issue-with-atom-selection-mddf-calculation-complexmixtures-jl-from-python/129604/2 "2025-06-03T16:34:29Z")

</div>

Thanks for the feedback!

Actually that is a limitation of the selection syntax we implemented so far in the PDBTools.jl package, which is a dependency of ComplexMixtures.jl.

The best alternative is to provide, to the `select` function, an anonymous Julia function, as:

```julia
using PDBTools
protein = select(atoms, at -> isprotein(at) && resnum(at) in (7, 8, 9, 391, 392, 393, 72))

```

The `at -> ....` should be read as "given the atom `at`, return `true` if the `at` satisfies conditions provided, and `&&` means “and”.

You can also define your own functions to select interesting things, and then use them as arguments to the `select` function, such as:

```julia
using PDBTools
select_my_residues(at) = isprotein(at) && resnum(at) in (7, 8, 9, 391, 392, 393, 72)
protein = select(atoms, select_my_residues)

```

FWIW, the issue there is that, using the string selection, you would need to write `"resnum 7 or resnum 8 or resnum 9 ... etc"`. which is of course anoying in this case.

Let me know if this solves your issue.

Ps. The `select` and `read_pdb` functions are from the `PDBTools` package, and I’m sort of suprised that `read_pdb("*.pdb")` is working for you, I would expect an explicit file name there.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [June 3, 2025, 4:37pm UTC](https://discourse.julialang.org/t/issue-with-atom-selection-mddf-calculation-complexmixtures-jl-from-python/129604/3 "2025-06-03T16:37:04Z")

</div>

The use of Julia functions to define selections is documented here: [Selections · PDBTools.jl](https://m3g.github.io/PDBTools.jl/stable/selections/#Use-Julia-functions-directly)

---

<div class="post-metadata">

**Author:** ![SnehaSahuvs4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/snehasahuvs4/32/217139_2.png) [@SnehaSahuvs4](https://discourse.julialang.org/u/SnehaSahuvs4)\
**Post date:** [June 3, 2025, 5:00pm UTC](https://discourse.julialang.org/t/issue-with-atom-selection-mddf-calculation-complexmixtures-jl-from-python/129604/4 "2025-06-03T17:00:23Z")

</div>

Dear Leandro

Thanks a lot for your quick response, i will try that first thing in the morning.

Best regards  
Sneha

---

<div class="post-metadata">

**Author:** ![SnehaSahuvs4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/snehasahuvs4/32/217139_2.png) [@SnehaSahuvs4](https://discourse.julialang.org/u/SnehaSahuvs4)\
**Post date:** [June 4, 2025, 4:58am UTC](https://discourse.julialang.org/t/issue-with-atom-selection-mddf-calculation-complexmixtures-jl-from-python/129604/5 "2025-06-04T04:58:58Z")

</div>

Dear Leandro,

I’m explicitly giving pdb file name in read\_pdb(“\*.pdb”), and I’m using Python for the job. Can you please further suggest how to achieve multiple residue selection in Python?

Thank you!  
Best regards  
Sneha

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [June 4, 2025, 11:46am UTC](https://discourse.julialang.org/t/issue-with-atom-selection-mddf-calculation-complexmixtures-jl-from-python/129604/6 "2025-06-04T11:46:51Z")

</div>

One alternative is to use a python function to create the required string. For example, here it could be:

```python
import ComplexMixtures as cm
atoms = readPDB("system.pdb")
protein = cm.select(atoms, "protein")

def select_my_residues(protein) :
    s = "resnum 7"
    for i in (8, 9, 391, 392, 393, 72) :
        s += " or resnum " + str(i)
    return cm.select(protein, s)

my_residues = select_my_residues(protein)

```

the `select_my_residues` function just creates the string `"resnum 7 or resnum 8 or resnum 9... etc"` and uses it to select the corresponding atoms from the `protein` object, which contains the protein atoms.

I’ll see if we can provide better alternatives.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [June 4, 2025, 6:55pm UTC](https://discourse.julialang.org/t/issue-with-atom-selection-mddf-calculation-complexmixtures-jl-from-python/129604/7 "2025-06-04T18:55:49Z")

</div>

Hi again. I’ve made some updates on the packages that might be helpful.

First, update the packages with (in python):

```python
import juliacall as jl
jl.Pkg.update()

```

You should get ComplexMixtures.jl version 2.13.0 and PDBTools.jl version 3.0.0 among the updates.

Then, update (copy the new version) of the [ComplexMixtures.py](https://m3g.github.io/ComplexMixtures.jl/stable/assets/ComplexMixtures.py) python module (updated in the manual [here](https://m3g.github.io/ComplexMixtures.jl/stable/python/#python)).

The script is mostly identical. But the news is that, if you have [VMD](https://www.ks.uiuc.edu/Research/vmd/) installed, you can use all the features of the VMD selection syntax with the `cm.select_with_vmd` function. For example:

```python
>>> import ComplexMixtures as cm
>>> atoms = cm.read_pdb("system.pdb")
>>> my_residues = cm.select_with_vmd(atoms, "resid 7 8 9 391 392 393 72")
>>> my_residues
Julia: [ Atom(95N-GLY7P), Atom(96HN-GLY7P), Atom(97CA-GLY7P), Atom(98HA1-GLY7P)…

```

The selection string `resid ...` is just the exact same string that would be used within VMD to select the desired subgroup.

I hope this helps. The scripts in the manual where updated to provide this information.

---

<div class="post-metadata">

**Author:** ![SnehaSahuvs4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/snehasahuvs4/32/217139_2.png) [@SnehaSahuvs4](https://discourse.julialang.org/u/SnehaSahuvs4)\
**Post date:** [June 5, 2025, 5:28am UTC](https://discourse.julialang.org/t/issue-with-atom-selection-mddf-calculation-complexmixtures-jl-from-python/129604/8 "2025-06-05T05:28:24Z")

</div>

Hi Leandro

Thank you so much for fixing the errors and updating the app — really appreciate your support!😁

Best,  
Sneha

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [June 5, 2025, 4:29pm UTC](https://discourse.julialang.org/t/issue-with-atom-selection-mddf-calculation-complexmixtures-jl-from-python/129604/9 "2025-06-05T16:29:48Z")

</div>

FWIW, now the PDBTools.jl package is updated (to version 3.1.0) and the selection syntax is more powerful, accepting the original code you posted here, and also parentheses, etc. You could do now:

```julia
cm.select(atoms, "(residue 1 3 7 5) and backbone")
#or
cm.select(atoms, "protein and resnum 2 7 39 81")

```

for example.

Just update the packages using

```julia
import juliacall as jl
jl.Pkg.update()

```

---

<div class="post-metadata">

**Author:** ![SnehaSahuvs4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/snehasahuvs4/32/217139_2.png) [@SnehaSahuvs4](https://discourse.julialang.org/u/SnehaSahuvs4)\
**Post date:** [June 9, 2025, 6:36am UTC](https://discourse.julialang.org/t/issue-with-atom-selection-mddf-calculation-complexmixtures-jl-from-python/129604/10 "2025-06-09T06:36:46Z")

</div>

Hi Leandro,  
I tried adjusting the `bin_width` parameter in Python using ComplexMixtures but couldn’t get it to work—could you please advise if it’s currently supported via the Python interface?

Thanks

Sneha

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [June 9, 2025, 9:43am UTC](https://discourse.julialang.org/t/issue-with-atom-selection-mddf-calculation-complexmixtures-jl-from-python/129604/11 "2025-06-09T09:43:55Z")

</div>

It is `binstep` and should work with, for example,

```julia
results = cm.mddf("./glyc50_sample.dcd", solute, solvent, cm.Options(binstep=0.05, bulk_range=(10.0,12.0)))

```

Can you show exactly what did you try?
