- The code opens a MATLAB figure file named "1.fig" and assigns the figure handle to the variable "figHandle".
- It specifies the desired output format as "png" and sets the output filename as "figure2.png".
- The "saveas" function is used to save the MATLAB figure as a 2D image in the specified format and filename.
- The saved image is read using the "imread" function, resulting in an RGB image stored in the variable "rgbImage".
- The "max" function is applied along the third dimension to convert the RGB image to grayscale. The resulting 2D grayscale image is stored in the variable "image2D".
- Finally, the "imshow" function is used to display the grayscale image.
Is there a code to convert/visualize a 3d figures (.fig) consisting of chemical bonds and structures into a 2d format, or into .pdb format?
4 views (last 30 days)
Show older comments
I have some figures of molecules which I want to convert from 3d into 2d for better visualization. I have attached the files for references. In figure 2, the red balls and the charges will remain as it is. Doing them manually is very time consuming and cumbersome. Any help to resolve this problem will be appreciated.
P.S 1.fig is the malab generated .fig file. Figure2.png provides how the structure may appear on visualization post processing.
0 Comments
Accepted Answer
Varun
on 7 Sep 2023
Hi,
As per my understanding to the question, you want to convert 3d figure (“.fig”) which consists of chemical bonds into 2d image (“.png”) or “.pdb” format.
Please refer the following code to convert 3d figure (“.fig”) to 2d (“.png”) image:
figFile = '1.fig';
figHandle = openfig(figFile);
% Set the desired output format and filename
outputFormat = 'png';
outputFilename = 'figure2.png';
% Save the 2D image
saveas(figHandle, outputFilename, outputFormat);
% Close the figure
close(figHandle);
% Read the RGB image
rgbImage = imread('figure2.png');
image2D = max(rgbImage,[],3);
% Display the 2D image
imshow(image2D);
Here is the breakdown of above code:
As per MATLAB version R2023a, MATLAB does not have any direct “.pdb” conversion functionality.
In order to transform the image into a ".pdb" file, you will require specific software or tools that are specifically designed for converting images into 3D molecular structures like Open Babel or PyMOL.
Hope this helps.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!