mirror of
https://github.com/chemistry-software/raymol.git
synced 2026-11-07 09:17:32 +00:00
Fix sdf parser and add sulfur and nitrogen atoms
This commit is contained in:
1 parent
ff9cd52ea1
commit
dd284e1191
4 files changed
+42
-13
No files matched your search
+21
-4
@@ -6,7 +6,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_ELEMENTS 120
|
||||
#define MAX_LINE_LENGTH 2048
|
||||
#define MAX_CSV_LINE_LENGTH 2048
|
||||
|
||||
typedef struct {
|
||||
char name[50];
|
||||
@@ -100,7 +100,7 @@ Element* parseCSV(const char* filename, int* element_count) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char line[MAX_LINE_LENGTH];
|
||||
char line[MAX_CSV_LINE_LENGTH];
|
||||
fgets(line, sizeof(line), file); // Skip the header line
|
||||
|
||||
*element_count = 0;
|
||||
@@ -156,14 +156,31 @@ Element* parseCSV(const char* filename, int* element_count) {
|
||||
return elements;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
int testParser() {
|
||||
int element_count;
|
||||
Element* elements = parseCSV("resources/periodictable.csv", &element_count);
|
||||
if (elements) {
|
||||
for (int i = 0; i < element_count; i++) {
|
||||
printf("Element: %s (%s), Atomic Mass: %.2f, Atomic Radius: %.2f\n", elements[i].name, elements[i].symbol, elements[i].atomic_mass, elements[i].electron_affinity);
|
||||
printf("Element: %s (%s)\n", elements[i].name, elements[i].symbol);
|
||||
printf("Atomic Mass: %.2f\n", elements[i].atomic_mass);
|
||||
printf("Category: %s\n", elements[i].category);
|
||||
printf("Atomic Number: %d\n", elements[i].number);
|
||||
printf("Period: %d\n", elements[i].period);
|
||||
printf("Group: %d\n", elements[i].group);
|
||||
printf("Phase: %s\n", elements[i].phase);
|
||||
printf("Summary: %s\n", elements[i].summary);
|
||||
printf("Shells: %s\n", elements[i].shells);
|
||||
printf("Electron Configuration: %s\n", elements[i].electron_configuration);
|
||||
printf("Electron Configuration Semantic: %s\n", elements[i].electron_configuration_semantic);
|
||||
printf("Electron Affinity: %.2f\n", elements[i].electron_affinity);
|
||||
printf("Electronegativity Pauling: %.2f\n", elements[i].electronegativity_pauling);
|
||||
printf("Ionization Energies: %s\n", elements[i].ionization_energies);
|
||||
printf("CPK Hex Color: %s\n", elements[i].cpk_hex);
|
||||
printf("Block: %s\n", elements[i].block);
|
||||
}
|
||||
free(elements);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "debug.h"
|
||||
#include "elementdata.c"
|
||||
#include "raylib.h"
|
||||
#include "sdfparse.c"
|
||||
#include <complex.h>
|
||||
@@ -25,6 +26,9 @@ int main(int argc, char *argv[]) {
|
||||
Molecule mol = parseSDF("./resources/sildenafil.sdf");
|
||||
// normalizeCoordinates(&mol, screenWidth, screenHeight);
|
||||
|
||||
int element_count;
|
||||
Element* elements = parseCSV("resources/periodictable.csv", &element_count);
|
||||
|
||||
D printf("Number of atoms: %d\n", mol.num_atoms);
|
||||
for (int i = 0; i < mol.num_atoms; i++) {
|
||||
D printf("Atom %d: %s (%.4f, %.4f, %.4f) - neighbours: %d\n", i + 1,
|
||||
@@ -133,7 +137,8 @@ int main(int argc, char *argv[]) {
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// TODO: Unload all loaded data (textures, fonts, audio) here!
|
||||
free(elements);
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
@@ -144,22 +149,27 @@ int main(int argc, char *argv[]) {
|
||||
void drawAtom(Atom atom) {
|
||||
Color color;
|
||||
float radius;
|
||||
int scalingFactor = 100;
|
||||
|
||||
// radius is empirical from https://en.wikipedia.org/wiki/Atomic_radii_of_the_elements_(data_page)
|
||||
if (strcmp(atom.atom_type, "C") == 0) {
|
||||
color = BLACK;
|
||||
radius = 70.0f / 100;
|
||||
radius = 70.0f / scalingFactor;
|
||||
} else if (strcmp(atom.atom_type, "O") == 0) {
|
||||
color = RED;
|
||||
radius = 60.0f / 100;
|
||||
radius = 60.0f / scalingFactor;
|
||||
} else if (strcmp(atom.atom_type, "H") == 0) {
|
||||
color = LIGHTGRAY;
|
||||
radius = 25.0f / 100;
|
||||
radius = 25.0f / scalingFactor;
|
||||
} else if (strcmp(atom.atom_type, "S") == 0) {
|
||||
color = YELLOW;
|
||||
radius = 100.0f / 100;
|
||||
radius = 100.0f / scalingFactor;
|
||||
} else if (strcmp(atom.atom_type, "N") == 0) {
|
||||
color = BLUE;
|
||||
radius = 65.0f / scalingFactor;
|
||||
} else {
|
||||
color = GRAY;
|
||||
radius = 25.0f / 100;
|
||||
radius = 25.0f / scalingFactor;
|
||||
}
|
||||
|
||||
DrawSphereWires((Vector3){atom.x, atom.y, atom.z}, radius, 25, 25, color);
|
||||
|
||||
+5
-3
@@ -39,11 +39,13 @@ Molecule parseSDF(const char *filename) {
|
||||
char line[MAX_LINE_LENGTH];
|
||||
while (fgets(line, MAX_LINE_LENGTH, file) != NULL) {
|
||||
// break if you reach M END
|
||||
if (strncmp(line, "M END", 6) == 0)
|
||||
if (strncmp(line, "M END", 6) == 0) {
|
||||
D printf("Reached END\n");
|
||||
break;
|
||||
}
|
||||
|
||||
// Ignore the line with bond and atom count, molfile version etc.
|
||||
if (isdigit(line[0]) && isdigit(line[2]))
|
||||
// continue of line contains V2000 or V3000
|
||||
if (strstr(line, "V2000") || strstr(line, "V3000"))
|
||||
continue;
|
||||
|
||||
// Parse the atoms and their coordinates
|
||||
|
||||
Reference in new issue
Block a user