Skip to content

Commit

Permalink
Merge pull request #73 from pyscal/fix_delete_bug
Browse files Browse the repository at this point in the history
Fix delete bug
  • Loading branch information
srmnitc authored Apr 5, 2024
2 parents ea39871 + d3f2f54 commit 5c8f014
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.5
current_version = 0.2.6
commit = True
tag = False

Expand Down
16 changes: 4 additions & 12 deletions pyscal_rdf/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def delete(self, ids=None, indices=None, condition=None, selection=False):
masks = self.atoms._generate_bool_list(ids=ids, indices=indices, condition=condition, selection=selection)
delete_list = [masks[self.atoms["head"][x]] for x in range(self.atoms.ntotal)]
delete_ids = [x for x in range(self.atoms.ntotal) if delete_list[x]]
actual_natoms = self.natoms
self.atoms._delete_atoms(delete_ids)

if self.graph is not None:
Expand All @@ -257,7 +258,7 @@ def delete(self, ids=None, indices=None, condition=None, selection=False):
self.add_vacancy(c, number=val)
#now we need to re-add atoms, so at to remove
self.graph.graph.remove((self.sample, CMSO.hasNumberOfAtoms, None))
self.graph.graph.add((self.sample, CMSO.hasNumberOfAtoms, Literal(self.natoms-val, datatype=XSD.integer)))
self.graph.graph.add((self.sample, CMSO.hasNumberOfAtoms, Literal(actual_natoms-val, datatype=XSD.integer)))
#revamp composition
#remove existing chem composution
chemical_species = self.graph.graph.value(self.sample, CMSO.hasSpecies)
Expand Down Expand Up @@ -288,23 +289,14 @@ def delete(self, ids=None, indices=None, condition=None, selection=False):
position_identifier = self.graph.graph.value(URIRef(f'{self.sample}_Position'), CMSO.hasIdentifier).toPython()
species_identifier = self.graph.graph.value(URIRef(f'{self.sample}_Species'), CMSO.hasIdentifier).toPython()

#open the file for reading
with open(filepath, 'r') as fin:
data = json.load(fin)
positions = data[position_identifier]['value']
species = data[species_identifier]['value']

#clean up items
positions = [pos for count, pos in enumerate(positions) if count not in delete_ids]
species = [pos for count, pos in enumerate(species) if count not in delete_ids]

datadict = {
position_identifier:{
"value": positions,
"value": self.schema.atom_attribute.position(),
"label": "position",
},
species_identifier:{
"value": species,
"value": self.schema.atom_attribute.species(),
"label": "species",
},
}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='pyscal_rdf',
version='0.2.5',
version='0.2.6',
author='Abril Azocar Guzman, Sarath Menon',
author_email='[email protected]',
description='Ontology based structural manipulation and quering',
Expand Down

0 comments on commit 5c8f014

Please sign in to comment.