-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#4880 – Add changes according new requirements for IDT aliases
- Loading branch information
Showing
12 changed files
with
217 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 2 additions & 15 deletions
17
packages/ketcher-macromolecules/src/components/shared/IDTAliases/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/ketcher-macromolecules/src/hooks/useIDTAliasesTextForMonomer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { | ||
AttachmentPointName, | ||
IKetIdtAliases, | ||
PolymerBond, | ||
Sugar, | ||
} from 'ketcher-core'; | ||
import { useMemo } from 'react'; | ||
|
||
type Props = { | ||
idtAliases: IKetIdtAliases | undefined; | ||
attachmentPointsToBonds?: Record<AttachmentPointName, PolymerBond | null>; | ||
}; | ||
|
||
const useIDTAliasesTextForMonomer = ({ | ||
idtAliases, | ||
attachmentPointsToBonds, | ||
}: Props) => { | ||
return useMemo(() => { | ||
if (!idtAliases) { | ||
return null; | ||
} | ||
|
||
const { base, modifications } = idtAliases; | ||
|
||
// For preview on canvas | ||
if (attachmentPointsToBonds) { | ||
if (!modifications) { | ||
return null; | ||
} | ||
|
||
const { endpoint5, internal, endpoint3 } = modifications; | ||
|
||
const { R1, R2 } = attachmentPointsToBonds; | ||
// Handle phosphate exclusively | ||
if (base === 'Phos') { | ||
if (R1 !== null && R1.firstMonomer instanceof Sugar) { | ||
return null; | ||
} | ||
} | ||
|
||
if (R1 !== null && R2 === null) { | ||
return endpoint3 ?? internal; | ||
} else if (R1 === null && R2 !== null) { | ||
return endpoint5 ?? internal; | ||
} else if (R1 !== null && R2 !== null) { | ||
return internal ?? endpoint5 ?? endpoint3; | ||
} else { | ||
return endpoint5 ?? internal ?? endpoint3; | ||
} | ||
} | ||
|
||
// For preview in library | ||
if (!modifications) { | ||
return base; | ||
} | ||
|
||
const allModificationsHaveSameBase = Object.values(modifications).every( | ||
(modification) => modification.includes(base), | ||
); | ||
|
||
if (allModificationsHaveSameBase) { | ||
return base; | ||
} | ||
|
||
const baseToPositionsMap: Record<string, string[]> = {}; | ||
Object.values(modifications).forEach((modification) => { | ||
const [position, base] = [modification.charAt(0), modification.slice(1)]; | ||
baseToPositionsMap[base] = baseToPositionsMap[base] | ||
? [...baseToPositionsMap[base], position] | ||
: [position]; | ||
}); | ||
|
||
return Object.entries(baseToPositionsMap) | ||
.map(([base, positions]) => { | ||
return `(${positions.join(', ')})${base}`; | ||
}) | ||
.join(', '); | ||
}, [idtAliases, attachmentPointsToBonds]); | ||
}; | ||
|
||
export default useIDTAliasesTextForMonomer; |
Oops, something went wrong.