Skip to content

Commit dcc41ba

Browse files
fix(file IO), fix(global initialization), fix(mass output), feat(channel-bound atoms) (#7)
* Minor file IO bug fix Fixed a minor bug related to file IO. Description: Not providing a .rad file for read_from_CIF, read_from_V1 and read_from_ARC resulted in a type error. Code to reproduce: from pyzeo.netstorage import AtomNetwork atmnet = AtomNetwork.read_from_CIF("EDI.cif") Example error output: File "src/pyzeo/extension.pyx", line 512, in pyzeo.extension.AtomNetwork.read_from_CIF TypeError: expected bytes, NoneType found Comment: A unit test "test_read_file.py" was added for validation. * Minor global state pollution bug fix Fixed a minor bug related to global state pollution of atomic property tables. Description: The global atomic property tables are not reevaluted in subsequent calculations if only using default zeo++ provided values. Example: Reading an AtomNetwork from a file using default Zeo++ atomic radii does not correctly reinitialize the default atomic radii if an AtomNetwork was read in beforehand using custom atomic radii. Code to reproduce: from pyzeo.netstorage import AtomNetwork from pyzeo.extension import lookupRadius atmnet = AtomNetwork.read_from_CSSR("MgO_vac1.cssr", rad_file="MgO.rad") atmnet = AtomNetwork.read_from_CSSR("EDI.cssr") element = "O" encoded_str = element.encode("utf-8") element_radius = lookupRadius(encoded_str) assert element_radius == 1.52, \ f"Wrong element radius. Expected 1.52, got {element_radius}" Example error output: AssertionError: Wrong element radius. Expected 1.52, got 1.84 Comment: A test "test_rad_table_init.py" was added for validation. * Bug fix for mass-related properties Mass-related properties in surface area and volume calculations are now displayed correctly. Description: Previously mass-related properties (Density, surface area and volume referenced to mass) were not displayed correctly. Example code: from pyzeo.netstorage import AtomNetwork from pyzeo.area_volume import volume from pyzeo.high_accuracy import high_accuracy_atomnet atmnet = AtomNetwork.read_from_CSSR("EDI.cssr") ha_atmnet = atmnet.copy() high_accuracy_atomnet(ha_atmnet, "DEF") vol_str = volume( atmnet, 1.2, 1.2, 50000, high_accuracy=True, high_accuracy_atmnet=ha_atmnet ) decoded_str = vol_str.decode("utf-8") print(decoded_str) Previous example output: @ No filename Unitcell_volume: 307.484 Density: 0 AV_A^3: 22.6493 AV_Volume_fraction: 0.07366 AV_cm^3/g: inf NAV_A^3: 0 NAV_Volume_fraction: 0 NAV_cm^3/g: -nan New example output: @ No filename Unitcell_volume: 307.484 Density: 1.62239 AV_A^3: 22.6493 AV_Volume_fraction: 0.07366 AV_cm^3/g: 0.0454022 NAV_A^3: 0 NAV_Volume_fraction: 0 NAV_cm^3/g: 0 Comment: The tests "test_areavol_mass.py" and "test_surface_area_mass.py" were added for validation of the mass-related outputs in the volume and surface area calculations. The test "test_mass_table_init.py" was added to test the correct initialization of the atomic mass table. * Added feature: Retrieve channel-bound atom IDs The IDs of atoms that bound a channel (set of accessible Voronoi nodes) that is found in the structure via Voronoi decomposition, can now be returned. New python methods: -VoronoiNetwork.find_channels(channel_radius: float) -> List[Channel], List[bool] Find channels in a Voronoi network. Identifies channels (sets of accessible Voronoi nodes) within the associated Voronoi network for a given probe radius. Args: channel_radius : float Radius of probe used to determine the accessibility of void space. Returns: 1) channels: List of Channel objects representing accessible channels 2) access_info: List of Booleans, where access_info[i] indicates if Voronoi node i is accessible for the probe -Channel.find_bounding_atoms(atmnet: AtomNetwork, vornet: VoronoiNetwork) -> List[int] Get the IDs of all atoms that bound this channel. An atom is considered to bound a channel if a Voronoi node of the channel is a member of the atom's Voronoi cell. Args: atmnet: AtomNetwork object The atom network structure of the associated channel vornet: VoronoiNetwork object The Voronoi network structure of the associated channel Returns: List of indices of the atoms that bound this channel New python properties: -AtomNetwork.atoms: List[Atom] -Atom.type: str Newly declared Cython attributes: -VoronoiNetwork.bvcells -VoronoiNetwork.has_bvcells Basic usage example: from pyzeo.netstorage import AtomNetwork atmnet = AtomNetwork.read_from_CSSR("EDI.cssr") probe_radius = 1.5 vornet, _, _ = atmnet.perform_voronoi_decomposition() channels, access_info = vornet.find_channels(probe_radius) num_accessible = access_info.count(True) print(f"Found {len(channels)} channels in the structure") print(f"Accessibility info for {len(access_info)} nodes") print(f"Number of accessible nodes {num_accessible}") for channel in channels: atom_ids = channel.find_bounding_atoms(atmnet, vornet) * Restructured tests and small test bug fix
1 parent 0462b04 commit dcc41ba

16 files changed

Lines changed: 645 additions & 30 deletions

src/channel.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ CHANNEL::CHANNEL(PORE *p){
801801
unitCells = p->unitCells;
802802
ucNodes = p->ucNodes;
803803
dimensionality = p->dimensionality;
804+
idMappings = p->idMappings;
804805
basis[0][0]=p->basis[0][0];basis[0][1]=p->basis[0][1];basis[0][2]=p->basis[0][2];
805806
basis[1][0]=p->basis[1][0];basis[1][1]=p->basis[1][1];basis[1][2]=p->basis[1][2];
806807
basis[2][0]=p->basis[2][0];basis[2][1]=p->basis[2][1];basis[2][2]=p->basis[2][2];

src/networkinfo.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ stripAtomNameInternalFlag = value;
3333

3434
/** Fills the radius table with several default values. */
3535
void initializeRadTable(){
36+
radTable.clear();
3637
//radTable.insert(pair <string,double> ("Symbol", vdW_Radius));
3738
radTable.insert(pair <string,double> ("H", 1.09));
3839
radTable.insert(pair <string,double> ("D", 1.09));
@@ -154,6 +155,7 @@ radTable.insert(pair <string,double> ("Ds", 2));
154155
* threshold +0.4A
155156
* */
156157
void initializeCovRadTable(){
158+
covRadTable.clear();
157159
//covRadTable.insert(pair <string,double> ("Symbol", Covalent_Radius));
158160
covRadTable.insert(pair <string,double> ("H", 0.23));
159161
covRadTable.insert(pair <string,double> ("D", 0.23));
@@ -271,6 +273,7 @@ covRadTable.insert(pair <string,double> ("Ds", 1.5));
271273
/** Fills the mass table with several default values
272274
** in units of g/mole. */
273275
void initializeMassTable(){
276+
massTable.clear();
274277
//massTable.insert(pair <string,double> ("Symbol", Atomic_Weight));
275278
massTable.insert(pair <string,double> ("H", 1.008));
276279
massTable.insert(pair <string,double> ("D", 2.0));
@@ -388,6 +391,7 @@ massTable.insert(pair <string,double> ("Ds", 271));
388391

389392
/** Fills atom metal/nonmetal information **/
390393
void initializeAtomCharacterTable(){
394+
atomicCharacterTable.clear();
391395
// value set to true if atom is metal
392396

393397
// atomicCharacterTable.insert(pair <string,bool> ("Symbol",true));
@@ -508,6 +512,7 @@ void initializeAtomCharacterTable(){
508512
/** Fills the atomic number table with atomic number of all elements
509513
** */
510514
void initializeAtomicNumberTable(){
515+
atomicNumberTable.clear();
511516
atomicNumberTable.insert(pair <string,int> ("H", 1));
512517
atomicNumberTable.insert(pair <string,int> ("D", 1));
513518
atomicNumberTable.insert(pair <string,int> ("He", 2));

src/pyzeo/extension.pxd

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ from libcpp.string cimport string
1212
from libcpp.vector cimport vector
1313
from libcpp.map cimport map as cmap
1414
from libcpp.set cimport set as cset
15+
from libcpp cimport bool as cpp_bool
1516

1617
#=============================================================================
1718
# geometry
@@ -78,12 +79,14 @@ cdef extern from "../networkinfo.h":
7879
cdef extern from "../channel.h":
7980
cdef cppclass CHANNEL:
8081
CHANNEL() except +
82+
cmap[int, int] idMappings
83+
void findBoundingAtoms(ATOM_NETWORK*, vector[BASIC_VCELL], vector[int])
8184

8285
cdef extern from "../channel.h" namespace "CHANNEL":
83-
cdef c_findChannelsInDijkstraNet "findChannels"(DIJKSTRA_NETWORK*,
84-
vector[bint] *, vector[CHANNEL] *)
85-
cdef c_findChannelsInVorNet "findChannels"(VORONOI_NETWORK*, double,
86-
vector[bint] *, vector[CHANNEL] *)
86+
cdef void c_findChannelsInDijkstraNet "CHANNEL::findChannels"(DIJKSTRA_NETWORK*,
87+
vector[cpp_bool] *, vector[CHANNEL] *)
88+
cdef void c_findChannelsInVorNet "CHANNEL::findChannels"(VORONOI_NETWORK*, double,
89+
vector[cpp_bool] *, vector[CHANNEL] *)
8790

8891
cdef class Channel:
8992
cdef CHANNEL* thisptr
@@ -141,7 +144,7 @@ cdef extern from "../networkstorage.h":
141144
ATOM() except +
142145
double x, y, z
143146
double radius
144-
#string type
147+
string type
145148
#int specialID
146149
double mass
147150
double charge
@@ -200,7 +203,7 @@ cdef extern from "../network.h":
200203

201204
cdef void loadRadii(ATOM_NETWORK*)
202205

203-
cdef void loadMass(bool, ATOM_NETWORK*)
206+
cdef void loadMass(bint, ATOM_NETWORK*)
204207

205208
cdef extern from "../area_and_volume.h":
206209
cdef void visVoro(char* name, double probeRad, int skel_a, int skel_b, int skel_c,
@@ -230,8 +233,13 @@ cdef class VoronoiNode:
230233
cdef class VoronoiNetwork:
231234
"""
232235
Cython wrapper class for Zeo++ VORONOI_NETWORK class.
236+
Contains a pointer to VORONOI_NETWORK, a vector
237+
of BASIC_VCELL objects and a flag denoting whether
238+
the BASIC_VCELL vector has already been populated.
233239
"""
234240
cdef VORONOI_NETWORK* thisptr
241+
cdef vector[BASIC_VCELL] bvcells
242+
cdef bint has_bvcells
235243

236244
#=============================================================================
237245
# netstorage
@@ -377,4 +385,4 @@ cdef extern from "../holograms.h":
377385
#=============================================================================
378386
# string_add
379387
cdef extern from "../string_additions.h":
380-
cdef int strCmpList(vector[string] list, string str)
388+
cdef int strCmpList(vector[string] list, string str)

0 commit comments

Comments
 (0)