Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update delete method to modify files #71

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion pyscal_rdf/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,35 @@ def delete(self, ids=None, indices=None, condition=None, selection=False):
self.graph.add((chemical_species, CMSO.hasElement, element))
self.graph.add((element, RDF.type, CMSO.Element))
self.graph.add((element, CMSO.hasSymbol, Literal(e, datatype=XSD.string)))
self.graph.add((element, CMSO.hasElementRatio, Literal(r, datatype=XSD.float)))
self.graph.add((element, CMSO.hasElementRatio, Literal(r, datatype=XSD.float)))

#we also have to read in file and clean it up
filepath = self.graph.graph.value(URIRef(f'{self.sample}_Position'), CMSO.hasPath).toPython()
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,
"label": "position",
},
species_identifier:{
"value": species,
"label": "species",
},
}
outfile = os.path.join(self.graph.structure_store, str(self._name).split(':')[-1])
json_io.write_file(outfile, datadict)


def __delitem__(self, val):
Expand Down
Loading