CCP4 file to a Python 3 numpy array or similar workaround I would like to merge together several ccp4 formatted density maps (and do a few minor things).

So ideally I would like to open the ccp4/mrc files as numpy arrays in Python 3 and save the array as a ccp4 file. CCTBX can open ccp4 maps as numpy arrays, but I really would like to avoid using Python 2.7 for various reasons.

This is to be used for constraining energy minimisation in PyRosetta using the pyrosetta.rosetta.protocols.electron_density.SetupForDensityScoringMover mover/sampler. But its pyrosetta.rosetta.core.scoring.electron_density.getDensityMap data loader only likes ccp4/mrc files (density maps) and not mtz files (structure factor maps).

From what I can tell there is no way to fudge a ccp4 map from a mtz map, correct? The fact that only ePDB provides ccp4 maps makes me want to use mtz files.

CCP4's Blend can merge datasets but uses only mtz files...
You can use Gemmi.

import gemmi
ccp4_map = gemmi.read_ccp4_map('my.map')
ccp4_map.setup()  # optional
np_array = numpy.array(ccp4_map.grid, copy=False)
# ...
ccp4_map.write_ccp4_map('out.ccp4')


The setup() call expands data to the whole unit cell.
The numpy array above accesses the data through Python's Buffer Protocol (it does not copy the data). So changing values in numpy array changes gemmi.Ccp4Map.

You can also use gemmi to read mtz file and transform map coefficients to a real-space map, see https://gemmi.readthedocs.io/en/latest/hkl.html.